2017-05-29 121 views
0

我想要在不使用「runat」屬性的情況下點擊html按鈕時獲取html文本框的值。我需要在代碼後面執行它,是否有可能?當html按鈕被點擊時獲取Html文本框的值

<button id="button1" onclick="btnclick">Click Here</button><input type="text" id="txtBox1" name="txtBox12" /> 

和我的代碼後面是這樣的:

protected void btnclick(object sender, EventArgs e) 
     { 
      string name = Request.Form["txtBox12"]; 
      Response.Write(name); 
     } 

回答

0

MODIFIED

要訪問的任何控制在後面的代碼它需要有RUNAT =服務器屬性附加到它。

在你的情況,像你指出,你可以將輸入文本的價值到ASP隱藏字段,然後訪問

其在服務器端的按鈕點擊,但在這種情況下也你必須把隱藏字段值內部形式runat =服務器標籤。

<form id="form1" runat="server"> 
    <input type="text" id="txt" onkeyup="PassValue(this);";/> 
    <asp:HiddenField ID="hf" runat="server" /> 
    <asp:Button ID="Button1" runat="server" Text="Go" onclick="Button1_Click" /> 
</form> 
----------------------- 
<script type="text/javascript"> 
     function PassValue(obj) { 
      document.getElementById("hf").value = obj.value; 
     } 
</script> 
+0

但我想在後面 –

+0

代碼來執行代碼,我說:要訪問任何控制代碼背後需要有RUNAT =服務器屬性附加到它。 – Elis

+0

thak你我會試試 –