开发者

How do I Request data from an input field in ASP.NET?

Simple question. I have the following hidden input field on my ASP.NET page:

<form id="userform" method="post" action="RankingPage.aspx">
    <input type="hidden" id="email" /开发者_运维百科>
    <input type="hidden" id="name" />
</form>

I'm trying to get the data from the field (in my code behind) like this:

protected void Page_Load(object sender, EventArgs e)
{
    string name = Request.Form["name"].ToString();
}

It's returning a null reference (which I'm assuming means it couldn't find the field). Am I doing this wrong?


oh geee, i was struggeling with this myself today.

I wanted to use the hidden html field to store info inbetween partial postbacks from my update panels.

I didn't want to use the 'runat ="server" ' on my hidden field as this then screws the ID (because i'm using masterpages).

the moment i changed mine from

<input type="hidden" id="manageremailHidden" />

to

<input type="hidden" id="manageremailHidden" name="manageremailHidden"/>

i was able to call the read the value from codebehind (on postback)

Public ReadOnly Property manageremailknown() As String
    Get
        Return Request.Form("manageremailHidden")
    End Get
End Property

cut a long story short.. you need to add the name property as well, otherwise it won't work.


perhaps you could use

<input type="hidden" runat="server" name="name" id="name" />

or use HiddenField control

then you can access it like Master.FindControl("name")


How about doing this:

<asp:HiddenField ID="HiddenSomething" runat="server" />

In the code behind do

HiddenSomething.Value
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜