html method=get 不将值传递给下一个 aspx 页面

发布于 2024-09-07 15:36:29 字数 1228 浏览 1 评论 0原文

我有一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

飘落散花 2024-09-14 15:36:29

如果您希望能够在服务器端访问这些控件,则需要向每个控件添加 runat="server" 属性。

另外,您引用的 TextBox 类型是您没有使用的 ASP.NET 控件。添加 runat="server" 标记后,您将使用的是 HtmlInputText

您可以通过使用 TextBox ASP.NET 控件而不是 元素来使用 TextBox 类型:

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

如果您的 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 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.

青丝拂面 2024-09-14 15:36:29

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 only this.YourInput.Text

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文