Looks like the "asp:HiddenField" doesn't have an "AutoPostBack" property, and I'm having problems with the "OnValueChanged" event... I need to call a function (C#) when I populate the hidden field, but in my case nothing happens. And I cannot use any scripts.
What could it be? =(开发者_C百科 Thank you by any response!
depending on what you're trying to do, you could add a property to your code-behind that sets the value of the HiddenField control, and then use that property instead. then, in the setter, do whatever you want.
i.e...
public string MyHiddenValue
{
get { return hiddenField.Value; }
set
{
hiddenField.Value = value;
if(MyHiddenValueChanged != null)
MyHiddenValueChanged(this, new EventArgs());
}
}
public event EventHandler MyHiddenValueChanged;
I am changing my complete answer because I was completely wrong. Darn.
I didn't know much about the OnValueChanged event for HiddenField before this (well, I actually didn't know anything about it, lol), but having checked out MSDN on the subject, it seems that the OnValueChanged event is there in order for you to detect if the value of the field has changed between postbacks (i.e. the user changed it in his or her browser since you last updated the value). If you change the value of the HiddenField when you post to the page, this doesn't fire the OnValueChanged event. If on the other hand a script on the page changed the HiddenField's value before the next page postback, then it would fire that event. So it's useless to you in your situation. My earlier suggestion to use an invisible TextBox and handle the TextChanged event is just as worthless, because the TextChanged event would fire only if the user changed it.
So, this doesn't answer your question, sorry about that.
Oh, and yes, here's the MSDN link: HiddenField Web Server Control
精彩评论