2

看起来“asp:HiddenField”没有“AutoPostBack”属性,并且我遇到了“OnValueChanged”事件的问题......当我填充隐藏字段时,我需要调用一个函数(C#),但是就我而言,没有任何反应。而且我不能使用任何脚本。

会是什么呢?=(感谢您的任何回复!

4

2 回答 2

2

根据您要执行的操作,您可以在代码隐藏中添加一个属性来设置 HiddenField 控件的值,然后改用该属性。然后,在二传手中,做任何你想做的事。

IE..

public string MyHiddenValue
{
    get { return hiddenField.Value; }
    set 
    {
        hiddenField.Value = value;
        if(MyHiddenValueChanged != null)
            MyHiddenValueChanged(this, new EventArgs());
    }
}
public event EventHandler MyHiddenValueChanged;
于 2010-07-08T21:24:40.477 回答
1

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

于 2010-07-08T18:38:27.140 回答