2014-10-17 16 views
-1

我有一些HTML輸入字段,我想在asp.net代碼中使用(即代碼背後的代碼 - C#)。如何在代碼c sharp中提交html輸入?

這是我的代碼:

<form id="contact_form" runat="server"> 
    <div> 
     <label for="name" >Name</label> 
     <input id="name" type="text" /> 
     <span id="nameinfo">what's your name?</span> 
    </div> 
    <div> 
+4

這不是一個具體的問題。有很多關於如何使用c#提交和處理html表單數據的教程。 – kevintechie 2014-10-17 01:57:51

回答

0

使用id作爲你的.cs文件的名稱

enter image description here

0

添加

RUNAT = 「服務器」

在例如,您的HTML輸入:

<input type="text" id="input1" runat="server" value="" /> 

那麼您可以在代碼中使用它隱藏文件

protected void Page_Load(object sender, EventArgs e) 
{ 
    input1.Value = "Welcome"; 
} 
1

解決方案1:

名稱添加到您的輸入是這樣的:

<input id="name" type="text" name="name" /> 

然後你可以閱讀在C#中發佈的值:

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

解決方案2:

如果您正在使用Web窗體,請用一個asp輸入:TextBox控件這樣的:

<asp:TextBox id="tbName" runat="server" /> 

而且你可以使用閱讀張貼的值:

string name = tbName.Text;