Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply

ASP Net - Problem Accessing WebForm Controls from a Dynamically created control (C#)

 
Thread Tools Search this Thread
Old 04-24-2004, 06:24 PM   #1
R Duke
 
Posts: n/a
Default Problem Accessing WebForm Controls from a Dynamically created control (C#)

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
  Reply With Quote
Old 04-24-2004, 09:40 PM   #2
R Duke
 
Posts: n/a
Default Re: Problem Accessing WebForm Controls from a Dynamically created control (C#)

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

  Reply With Quote
Old 04-25-2004, 08:21 AM   #3
=?Utf-8?B?SG1udA==?=
 
Posts: n/a
Default Re: Problem Accessing WebForm Controls from a Dynamically created control (C#)

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()
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47