2016-02-19 84 views
0

我已經創建了一個簡單的雲網絡角色,並在那裏有一個ASP.NET web表單。我有一個文本框,我應該能夠寫幾個文本,並在點擊提交按鈕後,我想顯示文本。文本框和按鈕都放在表單中。顯示文本框中的內容

因爲我是很新的Viasual工作室,我不知道如何通過編寫C#代碼aspx.cs類顯示文本

這是我曾嘗試:

的.aspx類:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body style="height: 435px"> 
    <form id="form1" runat="server"> 
     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
     <p> 
      <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" /> 
     </p> 
    </form> 
</body> 
</html> 

.aspx.cs類:

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

     } 

     protected void TextBox1_TextChanged(object sender, EventArgs e) 
     { 

     } 

     protected void Button1_Click(object sender, EventArgs e) 
     { 
      form1.InnerText = TextBox1.Text; 
     } 



    } 
} 
+0

請參閱一些基本教程第一。 –

回答

0

我會建議你通過微軟虛擬學院進行基礎培訓。無論如何,你可以在這裏做的是 - >添加一個標籤。假設它的ID是lbl1。在Button1_Click的方法,添加以下代碼

lbl1.Text = TextBox1.Text 
0

嘗試使用這就是佈局

<form id="form1" runat="server"> 
    <div runat="server" ID="fix"> 
     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
     <p> 
     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" /> 
     </p> 
    </div> 
</form> 

和變化碼

protected void Button1_Click(object sender, EventArgs e) 
    { 
     fix.InnerText = TextBox1.Text; 
    } 
相關問題