Thursday, March 22, 2012

What is the correct event to access controls and their values

I am sure someone has the answer to this very easy question:

What is the correct event to access controls and their values?

I am assuming this would be within the Load Event.

Are other possible events: Init Event, Unload Event, or PreRender Event ?

Im not a master programmer, but there is no "correct" event, its just what you want to happen, for example there can be an onclick event, or an ondatabind event just depends what control you are using and what you want to do. If you have your control on the page (gridview for example) in the properties window at the side click the yellow lighting bolt just below the drop down list at the top and that shows you all of the events for that control which you can click on and then it will take you to the section of your code and you cant write some code

e.g.

protectedvoid GridView1_SelectedIndexChanged(object sender,EventArgs e)

{

if (label1.Text != "Hello")

{

label1.Text.Color = Red

}

}


Hi NinjaSk8ter,

I'm not sure if I fully understand your question. First of all those events are the ASP.NET page life-cycle events.

http://msdn2.microsoft.com/en-us/library/ms178472.aspx

If the current request is a postback, you need to retrieve the value of the controls after Load event.


What is the correct event to access controls and their values: (This came from exam review questions)

Init, Load, Unload, PreRender


init - values aren't set yet

load - not all controls are built yet

unload - no controls available

prerender - controls and their values are available.

so of the four - prerender is the place to access control AND their values........

I think !! Smile

0 comments:

Post a Comment