0
Answer

dynamically generated web controls asp.net best method to access values at runtime?

markm75c

markm75c

16y
1.9k
1

I have a simple page i'm trying to do dynmaically.. i have a page called submitcomments.aspx with the .cs codebehind..

before i created everything in design view.. now i've ripped that out and added a asp panel to the page and created a procedure in my c# global.cs file called drawsubmitcomments

in that procedure i create the text boxes and buttons.

 

Problem is.. this code is not in the code behind for the page, so when i do commands like response.redirect.. i have to create a variable.. like say "Page varPage" and do a varPage.Response.redirect from the datalayer.cs procedure (which im not even sure if it will work)..

I also had to create the click event, which now resides in that cs file as well.. so on the click event i cant check the values for say txtBOX1.text etc.. unless i made these text boxes "global variables" to the datalayer.cs..

I'm not sure what the best practice is for something like this.. should i have done all the dynamic creation in the .cs codebehind file.. or make the variables global over there.. or something else?

Also.. if i try to dynamically create requiredfield validators.. they cant find the controls they are to check when the page loads.. any thoughts on this one too?

Thanks for any tips