473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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
Nov 18 '05 #1
2 2900
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

rd****@austin.rr.com (R Duke) wrote in message news:<9b*************************@posting.google.c 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

Nov 18 '05 #2
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(Sa*********@hotmail.com)
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: fumihiko | last post by:
Hi, I created an activex control (C++), and it uses another COM dll (C++). This COM dll links with a static library that dose some calculation. (both are debug multithreaded dll) I created a...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
7
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically...
3
by: Eric | last post by:
I have built a composite user web control that I want to create dynamically. The form will contain a variable number of these controls and as well some of the contents of the user web control...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web...
2
by: Richard Lionheart | last post by:
Hi All, I generated a WebForm and created a Virtual Directory for it IIS. But I got an error message (shown below) saying something like my app lacked appropriate privileges. David Wang...
1
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem:...
3
by: Ronald S. Cook | last post by:
I would like to put a label (or any control) on a webform all from the code. I.e. something like this: protected void Page_Load(object sender, EventArgs e) { Label TestLabel = new Label();...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.