Passing values from a parent web control to child web control

I have a parent control which called CONTROL1 and a child control witch called CONTROL2 I would link to pass a value from the parent control to the child control. In the parent control(CONTROL1) I have the following Event Handler .

private void btn_Handler(object sender, EventArgs e) {

     if (Page.IsPostBack) {

             // Send the officer names to the child controls.

            if(m_nameList.SelectedItem.Text != "")

            {

                        CONTROL2 .OfficerID = Int32.Parse(m_nameList.SelectedItem.Value);

}

}

But it does not pass the value to the child control and OfficerID return zero.

Am I missing something???

Thanks

0
Maysam
9/19/2005 6:28:20 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

6 Replies
1174 Views

Similar Articles

[PageSpeed] 1

In control2 add a property (In VB):

public property officer as int32
   get
      return officerID
   end get
   set (byVal Value as int32)
      officerID = value
   end set
end property

Then in control1:

   control2.officer = m_nameList.SelectedItem.Value


Nick

PS - Make sure you check your order of execution. Depending on where you are checking for the value of officerID sould be where you are having an issue.
0
nick
9/19/2005 7:18:35 PM

Thanks for your fast reply and I appreciate it. Actually I have OfficerID property in my child control (CONTROL2) as follow (In c#)

            public int OfficerID

{

                  get {

                        return m_OfficerID;

                  }

                  set {

                        m_OfficerID = value;

                  }

            }

Also in my parent control (CONTROL1) I have

CONTROL2 .OfficerID = Int32.Parse(m_nameList.SelectedItem.Value);

Which is what exactly what you mention. Right? I should missing something else!
Maysam

 

0
Maysam
9/20/2005 3:00:41 AM
Thats correct. Where are you calling CONTROL2 .OfficerID = Int32.Parse(m_nameList.SelectedItem.Value); from (i believe you said it was on button click?)? And then where are you using this ID (page load, button click, etc)?

Nick
0
nick
9/20/2005 1:23:43 PM

You are right. I am calling my CONTROL2 .OfficerID = Int32.Parse(m_nameList.SelectedItem.Value) from a button click handler   and I am using OficerID in the second control’s constructor.

0
Maysam
9/20/2005 2:05:23 PM
I believe thats where your issue is. You are setting the control after you are trying to access it. You will need to access the property from control 1 either onInit or on Page Load.


Nick
0
nick
9/20/2005 2:30:30 PM
Thanks Nick, I appreciate your help. I solve my provlem by using session variables.
Thanks again for your help and your time.

Maysam
0
Maysam
9/27/2005 4:16:07 AM
Reply:

Similar Artilces:

Web control in web control
Hi,There are two simple web user controls A and B, where B contains A. They just display the bunch of text boxes, so I do not need them even in tool pane. They sit in the same project next to web form.I noticed that web user control put on ASPX page does not appear in code behind, but if I create it with protected keyword and name being exactly the same as id it works fine. I can access such a web control from code behind and see the value assigned in IE. The problem is that the same routine does work for my A web control in B. When I assign the value IE, I keep getting null reference. ...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

Filling a textbox on a parent web user control from a child web form
Hi, I currently have a web user control (pf_imageselector.ascx) which is dynamically created (any number of times) on a parent web user control (pf_fillitems.ascx) which in turn has been loaded into a webform (default.aspx). On the user control is a text box called txbSelectedImage and a button. On click of the button run's this code: function OpenChild() { var strImageFile; var WinSettings = "height=580,width=630,status=yes,toolbar=no,menubar=no,location=no"; window.open("pf_stockimage.aspx", null, WinSettings); } Which obviously open a ch...

Datagrid not refreshing in Parent web control even after re-binding from Child web control?
Hello .....,               I have dropped a web user control (B) in one my web user control (A). Now (A) contains control (B). After proving some data in (B) to be binded to the DataGrid control used in (A), I call the DataBind. When debugging the Items, the Count property shows the number of Items correctly, but the datagrid doesn't seems to have rendered the updated datagrid content. Please help me out of this problemThanx and Regards,Hemant...

Clearing Web Controls Values from a Web Form
I have a web form and after a user submit it I want to clear the form so that they may submit another entry. I have seen examples in VB of how to loop thru a web form and clear the controls, but I need a C# solution. I have tried the following code, while it does not give me an error, it does not clear the controls on the form. Any suggestions? Thanks! foreach (Control parent in Page.Controls)         {             foreach (Control child in parent.Controls)           ...

web web web
Name: bahadir Email: sensiz_olmuyor_t1_at_hotmail.com Product: Firefox 2 Beta 2 Summary: web web web Comments: web sayfası yapmak Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.8.1b2) Gecko/20060821 Firefox/2.0b2 ...

web controls and web user control
i have a problem in a web form , I have a webform that contains a web user control which in turn contains a html input form ,the web control events don't fire up ,When I click button ,no effect ,I don't know what is the effect of the html form which is in the web user control on the web controls in the web form ?? can any one help me the web control event should be handle in the code behind page, is the event handler for the button you are clicking registered? You can try double clicking the button, should give you the default btn_click event handler in code behind. Also, make ...

Use Web Control In a Web Control
Is this possible?I am working with an aspx page that consists of many different web controls.One of the web controls contains search criteria.  One of the criteria is a date range where I am trying to add a popup calendar --> which is another web controlCan I register the popupcaledar control on the questionaire control?  I have tried, but nothing seems to be registered.Any ideas will GREATLY help.Relax and have some Home Brew!Prosecute the Owner - Don't PERSECUTE the Breed!Breed Specific Legislation targets the WRONG end of the LEASH! Without seeing your code we can'...

controlling an object in a web control from the page the web control is placed in
I have created a web control in vb.net that has an image button and an image. when it loads the image button is visible and the image is not. I want to be able from the page which "includes" the web control to set the image button to invisible and the image to visible. When I tried this, the main page didn't recognise the image button or the image (both < asp: objects). help would be gratefully appreciated. oh yeah, it's inline code so any code behind stuff will just confuse me ;) Some code please.-- Justin Lovell...

Pass data from Web User Control to Web Form
I have a Web Form that contains a Web User Control. The WUC displays dynamic content. I want to change the TITLE property of the Web Form, based on the contents of the WUC. For example, if the WUC displays information about Horses, I want to change the page title to "HORSES" by passing the string to the parent Web Form. I have tried playing with parameters and such, but I can't remember how I did this in the past. PLEASE HELP!~o0 Spin-Monkey Oo~ The best way to do this is by creating a public property on your web user control and accessing that from your web form. Check ...

Retreiving a value from a web form within a web user control
Hi  I have a page (web form) that retreives some data from a database. To be more specific: at some point when user clicks a button (in the web form) there is some ID number retreived from a database in code behind. At the same time the Visible property of the nestet web user control is chamged to true. I want than forward the ID to the web user control so that a grid view can load data from a database for that ID. How can I access that data (the ID) within a web user control context nested in that page?  Kind regards   Check this ;ink  http://www.codeproject.com/K...

Refresh Web form (parent) when submiting Web User Control
I got one Web form that contains one Web user control. The web form is displaying some data that is stored in database and Web User Control to edit this data and save the changes to database. When I press submit button in user control the data is getting stored in db, but Web form is not updated with this new changes ( i think this is because of the callback ). If I refresh the page then i see the changes. How can I make user control fire the refresh event in web form? If you have a answer pls give me a example or point to one tutorial, its much easier to understand! Thanks for your time!...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

Reusing custom web control in the same web control
Hello, I'm newbie in web development and of course asp.net. I am actually trying to build my first page and I'd like to know if it is possible to make a custom webcontrol that will contain itself. Let's say I want to draw a folder hierarchy in treeview-like structure. I thought I could make a control that will display a folder and if this folder contains subfolders then for each the control will include itself. Is this even possible? What would you suggest me to do to? Thanks in advance. TomTom Hagen http://thagen.dteam.info If the control can have child controls, then I s...

Web resources about - Passing values from a parent web control to child web control - asp.net.web-forms

Passing off - Wikipedia, the free encyclopedia
This article includes a list of references , related reading or external links , but its sources remain unclear because it lacks inline citations ...

Facebook Gets Passing Grade From Irish Agency Audit - AllFacebook
Facebook received its report card in the form of a detailed audit by the Office of the Irish Data Protection Commissioner, and its grades were ...

Whether passing the 9/11 Health Bill,... - Kirsten Gillibrand - Facebook
Whether passing the 9/11 Health Bill, repealing DADT, or my call to action for women, I have always urged New Yorkers to make their voices heard. ...

Thread: Buck-passing bullshit.
The Repubs are tempting fate, trying to allocate blame for Obama's loss in November. Obviously it's a little presumptuous. If Romney wins, it's ...

Scripting News: People are asking about the history of RSS today because of Aaron's passing.
People are asking about the history of RSS today because of Aaron's passing. In April 2004 I put together a timeline of the various specs that ...

AfroCat ◆ Cute and free pet game ◆ Perfect for passing the time! on the App Store
Read reviews, compare customer ratings, see screenshots, and learn more about AfroCat ◆ Cute and free pet game ◆ Perfect for passing the time!. ...

walmart donated a palette of water. everyone was great about passing the bottles back
Explore pinguino's photos on Flickr. pinguino has uploaded 16442 photos to Flickr.

Astronauts Mark Leonard Nimoy’s Passing - YouTube
NASA Astronaut Mike Fincke and ESA European Space Agency Astronaut Luca Parmitano reflect on the inspiration that actor Leonard Nimoy’s character ...

UAE remembers Zayed 10 years after his passing
Several activities will be taking place on Ramadan 19th marking the 10th anniversary of Sheikh Zayed’s passing.

Should IVF be used to avoid passing on mutations?
Should IVF be used to avoid passing on mutations?

Resources last updated: 1/7/2016 10:57:55 AM