html method=get 不将值传递给下一个 aspx 页面
我有一个简单的 html 页面,有 3 个文本框。
<form id="form1" method=get action="http://mysite.com/default.aspx" runat="server">
<div>
<input id="name" type="text" value="Amy" />
<input id="email" type="text" value="[email protected]"/>
<input id="phone" type="text" value="2125552512" />
</div>
<input id="Submit1" type="submit" value="submit" />
</form>
现在,当它加载 default.aspx 时,我在 page_load 的 vb 后端中有此代码。
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
页面已加载,但这些文本框为空。我做错了什么?
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="Amy" />
<input id="email" type="text" value="[email protected]"/>
<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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望能够在服务器端访问这些控件,则需要向每个控件添加
runat="server"
属性。另外,您引用的
TextBox
类型是您没有使用的 ASP.NET 控件。添加runat="server"
标记后,您将使用的是HtmlInputText
。您可以通过使用 TextBox ASP.NET 控件而不是
元素来使用
TextBox
类型:如果您的 ASP.NET 页面所做的只是处理请求从表单中,则无需引用任何文本框或输入控件 - 这是不可能的,因为它们不作为 ASP.NET 控件存在。您所需要做的就是从 Request.QueryString 读取值。
如果目的是让输入在 ASP.NET 页面上可见和/或可编辑,我建议将 HTML 表单移至 ASP.NET 页面中。
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 therunat="server"
tags isHtmlInputText
.You can use the
TextBox
type by using the TextBox ASP.NET control instead of the<input>
elements: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.
webform 的功能并不是这样的。
首先,您在表单中的输入需要是服务器控件: ex <
asp:TextBox runat="server" id="name" Text="value" />
然后在您的代码隐藏文件中不必经过
Page.FindControl("YourInput")
而只需经过this.YourInput.Text
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 onlythis.YourInput.Text