简体   繁体   中英

Access Input text on aspx page

I have a aspx page on my website. The html is as under

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

The web page loads with a edit box where I can input a name. Now I want to get it in my script. In my submit() function I try

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

but my name string is always blank? I have also tried Request["IDName"] but its still blank. Please help

I assume you want, your html input text's value accessible on to javascript code

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()" />

JS

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

if you want to do it in c#(code behind)

aspx(html)

<%@ 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>

C#

  namespace Test
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {

            }

            protected void Button1_Click(object sender, EventArgs e)
            {
                string yourval = TextBox1.Text.ToString();
            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM