I have an ASP.NET checkbox that based on certian logic I need to set its checked
value to true
server-side. This is easy enough, but it fires the wired up MyCheckBox_CheckedChanged(object sender, EventArgs e)
event as well.
That event's code is 100% ok, as long as it is called when the user checks the check box from the client. However, when I'm just trying to set that checkbox to be Checked = true;
server-side I don't want the code in the event to run.
The cleanest way I would like to approach this was to inspect the sender
object on the event and see if this event was really called by the client or not (like: http://msdn.microsoft.com/en-us/library/aa457091.aspx). However this did not yield any distinguishing information. It still looked like the checkbox being selected called it.
My 2nd thought is to set some session value and inspect this to basically return
if not being called by the user. I can easily do this, but I don't like using 'public flags' of sorts unless absolutely necessary. I'd rather (if at all possible) inspect the sender
or arguments
on that event to determine if that property was set server side on reload of data from the database, or if the user actually selected it.
I saw this Prevent postback on server-side property change and it was not a direct solution to my question, but rather a work around not applicable to my situation.
Is there a way to determine this was set solely server side so that I can bypass running this code?