服務器端控件text沒辦法綁定後臺成員變量的原因解釋
1。<asp:TextBox ID="TextBox1" runat="server" Text='<%=strDate %>'></asp:TextBox>
原因是這樣的,你這用的是服務器控件(runat="server")就得麻煩點
你先得在後臺寫個方法,如:
protected string GetNameCookie()
{
return strDate = DateTime.Now.ToString("yyyyMMdd");
} 然後在你的頁面(可以從頁面點右鍵然後選“組件設計器”然後選擇頁面的事件進行編輯)的prerender事件處理中寫一行:
this.DataBind();
最後前臺界面,所有需要這個函數的地方使用綁定語法,例如:
<asp:TextBox ID="TextBox1" runat="server" Text=" <%# this.GetNameCookie() %>" OnPreRender="TextBox1_PreRender"></asp:TextBox>
2。如果你用的不是服務器控件,如
<input id="input" type ="text" value=<%=strDate %> />就可以了!
原因是這樣的,你這用的是服務器控件(runat="server")就得麻煩點
你先得在後臺寫個方法,如:
protected string GetNameCookie()
{
return strDate = DateTime.Now.ToString("yyyyMMdd");
} 然後在你的頁面(可以從頁面點右鍵然後選“組件設計器”然後選擇頁面的事件進行編輯)的prerender事件處理中寫一行:
this.DataBind();
最後前臺界面,所有需要這個函數的地方使用綁定語法,例如:
<asp:TextBox ID="TextBox1" runat="server" Text=" <%# this.GetNameCookie() %>" OnPreRender="TextBox1_PreRender"></asp:TextBox>
2。如果你用的不是服務器控件,如
<input id="input" type ="text" value=<%=strDate %> />就可以了!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.