如标题.
解决方案 »
- .netFramework2.0下程序报分析器错误
- .net list集合参数类型动态设置
- ButtonField换成LinkButton问题···
- 在vs中 vs怎么把自定义的控件放到其他网页里?我一放就出错 vs就假死
- repeater中的图片自动变换
- 关于<%# DataBinder.Eval(Container.DataItem,"A_Text")%>的问题?
- 2个小问题
- ★为何写入SQL Server中的中文总是乱码?读出的也是?
- 谁有Visual Studio.NET下载地址?
- 懂http html高手解答下小弟疑惑
- 树形dropdownlist绑定N级例子
- 这些简单的js代码为什么不能正常运行?????????
应该要添写JS语句吧?
怎么JS添加?
<asp:button id="Button1" runat="server" Text="Button"></asp:button>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
***************************************************************
if(!Page.IsPostBack)
{
this.Button1.Attributes.Add("onclick","document.getElementById('Text1').value = new Date();return true;");
}
private void Button1_Click(object sender, System.EventArgs e)
{
this.TextBox2.Text = this.Text1.Value;//这里就可以得到客户端浏览器当前的时间了
}
但我还有一个问题不明白,为什么<INPUT id="Text1" type="hidden" name="Text1" runat="server">其中的runat="server"要在server运行
我个人认为应该是在客户端运行才对.
怎么在server运行就能得到client的系统时间,不明白
------------------------------------------------answer:
关键在这里:this.Button1.Attributes.Add("onclick","document.getElementById('Text1').value = new Date();return true;");
这行代码虽然写在cs里,但实际上是给Button1的客户端的onclick事件添加了一段脚本,这段脚本是在浏览器运行的,他把浏览器能获取的当前时间填入到一个文本框,那么回传服务器的时候,文本框的内容回传到服务器