![]() |
|
|
|||||||
![]() |
ASP Net - Problem Accessing WebForm Controls from a Dynamically created control (C#) |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Posts: n/a
|
I have tried everything I can think of to change the visible property
of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have a WebForm with some textboxes, dropdownlists, a panel, imagebutton and so on. When I click on the image button (which was created at design time) I dynamically build a table. In each of row of that new table I put several cells and one cell contains an image button. I am able to successfully get the event handler of this dynamically created image button to fire (regardless of the row I am clicking), but in the event handler I am setting the design'time created panel's visible property to true but it doesn't actually do anything. So I created a dummy textbox at design time and just tried to set the text value of that textbox in the same dynamically created image button event. It doesn't work. I know the event is firing because I have debugged through it, but it doesn't actually change the textbox text value even though the code runs. Why can't I access the design-time controls of the form from my dynamically created object's event handler? Here is my event handler code: string trackNum = e.CommandArgument.ToString(); this.lblArtistSearchType.Text = "Select Track " + trackNum + " Artists"; this.txtHiddenArtistSearch.Text = "Unhide"; this.txtHiddenArtistSearchType.Text = trackNum; this.pnlArtistSelection.Visible = true; <-- Doesn't work Thank you, Rodney |
|
|
|
#2 |
|
Posts: n/a
|
I am now just creating a session variable in the event handler for my
dynamically created control(Image button) as follows: private void LookupTrackArtist_Command(Object sender, CommandEventArgs e) { // Get the command argument string trackNum = e.CommandArgument.ToString(); Session["TrackSearch"] = trackNum; } And in the Page_Load (Where PostBack is true) event I am setting the visibility of the panel as follows: if (Session["TrackSearch"] != null) { this.pnlArtistSelection.Visible = true; } The problem now is that the Page_Load event seems to fire before the event so the Session variable is not there when the Page_Load fires. So I have to click on the dyanically created control (image button) twice before the panel becomes visible. What am I missing here? Thanks in advance for you help. Rodney (R Duke) wrote in message news:< om>... > I have tried everything I can think of to change the visible property > of a design time created control from a dynamically created control's > command event handler. > > Here is the scenario. > > I have a WebForm with some textboxes, dropdownlists, a panel, > imagebutton and so on. When I click on the image button (which was > created at design time) I dynamically build a table. In each of row of > that new table I put several cells and one cell contains an image > button. I am able to successfully get the event handler of this > dynamically created image button to fire (regardless of the row I am > clicking), but in the event handler I am setting the design'time > created panel's visible property to true but it doesn't actually do > anything. So I created a dummy textbox at design time and just tried > to set the text value of that textbox in the same dynamically created > image button event. It doesn't work. I know the event is firing > because I have debugged through it, but it doesn't actually change the > textbox text value even though the code runs. > > Why can't I access the design-time controls of the form from my > dynamically created object's event handler? > > Here is my event handler code: > string trackNum = e.CommandArgument.ToString(); > this.lblArtistSearchType.Text = "Select Track " + trackNum + " > Artists"; > this.txtHiddenArtistSearch.Text = "Unhide"; > this.txtHiddenArtistSearchType.Text = trackNum; > this.pnlArtistSelection.Visible = true; <-- Doesn't work > > Thank you, > > Rodney |
|
|
|
#3 |
|
Posts: n/a
|
Hi
First things first.. When u create a control DYNAMICALLY ... its yo responsibility to 'RECREATE' it every time a postback occurs ... that is because we work in a stateless envmt and every control(design-time) will be created by the page @ runtime EACH time the page is loaded (post-back) ... Also the VIEWSTATE of that control will be saved (by default) and even u'll observe that if u'll recreate yo control in post-back (i.e in yo Page_Load event) its viewstate will be automatically assigned to it !! Also to warn u that there certain :::Magical::: things that happen during debugging - that is sometines the behaviour while debugging the application and running it are not same !! If u can describe it in more simple manner it'd help both of us .. Tell me if it doesn't work() |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem in accessing CD Drives in VB/VB.Net 2.0. | priyamtheone | Software | 0 | 07-29-2008 04:49 PM |
| Dynamically added TreeNode Control not render my custom attribute | venkyzealous | Software | 0 | 05-10-2008 02:46 PM |
| how to create an new webform with codebehind dynamically using c# in asp.net?. | krish200 | Software | 1 | 12-18-2007 08:16 PM |
| Problem accessing query in the design mode MS access | shieldguy | Software | 0 | 11-07-2006 01:45 PM |
| I just want to know how to create a new webform in asp .net dynamically... | nkamalraj | Software | 1 | 05-28-2006 03:28 AM |