访问aspx页面上的输入文本

时间:2016-04-21 08:56:21

标签: javascript jquery asp.net

我的网站上有一个aspx页面。 html在

之下
<form>
  Name: <input type="text" name="IDName" id="IDName">
</form>
<input type="Button" id="btnCheck" value="Submit" style="width:200px;height:30px;" onclick="submit()" />

网页加载了一个编辑框,我可以在其中输入名称。现在我想在我的脚本中得到它。在我的submit()函数中,我尝试

string name = Request.Form["IDName"];

但是我的名字字符串总是空白的? 我也尝试过请求[&#34; IDName&#34;]但它仍然是空白的。请帮忙

1 个答案:

答案 0 :(得分:0)

我假设你想要,你的html输入文本的值可以访问javascript代码

<强> HTML

C[i] = new BTreeNode[length];

<强> JS

<form>
  Name: <input type="text" name="IDName" id="IDName">
</form>
<input type="Button" id="btnCheck" value="Submit" style="width:200px;height:30px;" onclick="submit()" />

如果您想在c#(代码隐藏)

中执行此操作

<强> ASPX(HTML)

function submit()
{
var yourValue=document.getElementById("IDName").value;
alert(yourValue);
}

<强> C#

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Test.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </div>
    </form>
</body>
</html>
相关问题