开发者

ASP.NET Hidden fields data only available in a postback? why?

According to MSDN hidden fields section,

In order for hidden-field values to be available during page processing, you must submit the page using an HTTP POST command. If you use hidden fields and a page is pro开发者_StackOverflow中文版cessed in response to a link or an HTTP GET command, the hidden fields will not be available.

If I add a HiddenField control at design time and set a value in it at design time or in the Init event in ASP.NET, why would I not be able to read/process the value when a page is first requested?


How have you defined your hidden field?

You need to make hidden field as runat="server" like this:

<input id="something" type="hidden" value="something that is hidden" runat="server" />

Then you will be able to access this field on server even if it is Get request.

protected void Page_Load(object sender, EventArgs e)
{
     Response.Write(string.Format("{0} came from hidden field", something.Value));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜