开发者

html method=get not passing values to the next aspx page

i have simple html page with 3 textboxes.

<form id="form1" method=get action="http://mysite.com/default.aspx" runat="server">
    <div>
        <input id="name" type="text" value="A开发者_如何学Pythonmy" />
        <input id="email" type="text"  value="amy@jf.com"/>
        <input id="phone" type="text" value="2125552512" />
    </div>
    <input id="Submit1" type="submit" value="submit" />
</form>

Now when it loads default.aspx i have this code in the vb backend on page_load.

Dim tbName As TextBox = Page.FindControl("Name")
Dim tbPhone As TextBox = Page.FindControl("Phone")
Dim tbEmail As TextBox = Page.FindControl("Email")
If page.request("name") & "" <> "" AndAlso tbname IsNot Nothing Then
    tbname.text = page.request("name") 
End If
If page.request("email") & "" <> "" AndAlso tbEmail IsNot Nothing Then
    tbEmail.text = page.request("email") & ""
end If
If page.request("phone") & "" <> "" AndAlso tbphone IsNot Nothing Then
    tbPhone.text = page.request("phone") & ""
End If

The page loads but is these textboxes are empty. what am i doing wrong?


If you want to be able to access those controls serverside, you'll need to add the runat="server" attribute to each of them.

Also, the TextBox type you're referencing is the ASP.NET control, which you aren't using. What you'd be using, once you add the runat="server" tags is HtmlInputText.

You can use the TextBox type by using the TextBox ASP.NET control instead of the <input> elements:

<asp:TextBox ID="name" runat="server" Value="Amy" />

If all your ASP.NET page is doing is processing the request from the form, then there's no need to reference any textbox or input controls - it won't be possible since they don't exist as ASP.NET controls. All you need to do is read the values from Request.QueryString.

If the intent is for the inputs to be visible and/or editable once they're on the ASP.NET page, I'd recommend moving the HTML form into your ASP.NET page.


it is not like this that webform functionate.

First, your input in your form needs to be server control: ex <asp:TextBox runat="server" id="name" Text="value" />

Then in your codebehind file you do not have to go through Page.FindControl("YourInput") but only this.YourInput.Text

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜