In Page PostBack control losing its reference

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All
I am a newbie to ASP.Net. I am creating controls dynamically in my code behind file. When I am debugging, in postback the controls reference are found to be undefined. I also used ctrl.Attributes.Add("runat","server") for the controls
But if I am adding the controls in .aspx file then it is holding the reference

Can anybody help me out
Thanks
Shravan.
 
Hi, Shravan,

On every postback to the server the page object gets instantiated and what
you work with is the instance. If your controls are "static" (added to the
html part of the page) the parser does the job to instantiate the control
objects and add the references to the page object. If you decide to go for
the harder way (dynamically add the controls, that is) you must redo
everything on every postback - create the controls, add them to the page,
attach events etc.

Hope this helps
Martin
Shravan said:
Hi All,
I am a newbie to ASP.Net. I am creating controls dynamically in my code
behind file. When I am debugging, in postback the controls reference are
found to be undefined. I also used ctrl.Attributes.Add("runat","server") for
the controls.
 
Back
Top