比如我在test.aspx里面写了一个JavaScript的函数test():
<script type="text/javascript">
function test()
{
alert("Test");
}
</script>
现在我想在test.aspx.cs某个文本框控件的textchange中调用这个函数
比如在:
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
//想在这里调用test()方法
}
应该怎么做呢?
这里先谢谢各位了!
<script type="text/javascript">
function test()
{
alert("Test");
}
</script>
现在我想在test.aspx.cs某个文本框控件的textchange中调用这个函数
比如在:
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
//想在这里调用test()方法
}
应该怎么做呢?
这里先谢谢各位了!
进行脚本注册
似乎不行,我用以下方法不管用,执行该语句后,id为name的div内容没有改变:
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "document.getElementById ('name').innerHTML='恭喜,该用户名可以注册';", true);
但如果把
document.getElementById ('name').innerHTML='恭喜,该用户名可以注册';
修改为:
alert('Test');
则程序可以顺利执行
不知道怎么回事,都是JavaScript代码
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", scriptStr, true);
参考http://www.clubdotnet.com/dispbbs.asp?boardid=6&id=45&page=1&star=1
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
如果你要用RegisterStartupScript这种方式来改变id为name的DIV内容,必须将此DIV放在 有"runat=server"的form中.其实你这样其实是舍近求远,直接用一个服务器端DIV控件,在后台直接用
name.innerHTML="该用户可以注册",何必用后台输出javascript这种弯路
function test()
{
alert("oec2003");
return false;
}
</script>c#代码: protected void Button1_Click(object sender, EventArgs e){
ClientScript.RegisterStartupScript(this.GetType(), "clear", "<script>test()</script>");
}