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 %> />就可以了!
本文介绍如何在ASP.NET中使用服务器控件TextBox动态显示日期,并提供了两种方法:一种适用于服务器控件,涉及页面预渲染事件及数据绑定;另一种适用于非服务器控件,直接在HTML标签中设置值。
277

被折叠的 条评论
为什么被折叠?



