在文本框中调用客户端和服务器端事件...
问题描述:
这是我的java脚本函数
hi this is my java script function
<script type="text/javascript">
function here()
{
return(confirm("YOU WANT"));
}
</script>
这是我的文本框...
this is my text box ...
<asp:TextBox ID="TextBox1" Onchange="return here()" runat="server"
AutoPostBack="True" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
这是我的cs代码
and this is my cs code
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
Response.Write("i will peroform data base task");
}
现在我的问题是...我的javascript功能返回true然后我的.cs页面函数也没有调用....
now my problem is ... my javascript function returning true then also my .cs page function is not calling....
答
亲爱的Dilip,
它不允许你一次调用Javascript事件和服务器端事件,这可以通过从客户端事件调用服务器端函数来实现。
使用jquery.post()来调用服务器端功能
http://api.jquery.com/jQuery.post/ [ ^ ]
或
使用pagemethods
http://www.dotnetcurry.com/ ShowArticle.aspx?ID = 109 [ ^ ]
或从服务器端调用java脚本函数活动。
如何调用javascript函数.cs文件 [ ^ ]
这对你有帮助。
谢谢
Dear Dilip,
It does not allow you to call Javascript event and server side event at a time, this can be achieved by calling server side function from client side event.
use jquery.post() to call a server side function
http://api.jquery.com/jQuery.post/[^]
or
use pagemethods
http://www.dotnetcurry.com/ShowArticle.aspx?ID=109[^]
or call java script function from server side event.
how to call javascript function .cs file[^]
This will helpful to you.
Thanks
使用 Onblur 更改文本框事件 Onchange ,例如,
Change your textbox event Onchange with Onblur like,
<asp:TextBox ID="TextBox1" Onblur="return here()" runat="server"
AutoPostBack="True" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
function here()
{
var result = confirm("YOU WANT");
if(result)
{
__doPostBack('UNIQUE NAME OF TEXT BOX', null);
}
else
{
return false;
}
}
<asp:TextBox ID="TextBox1" Onchange="return here()" runat="server"
AutoPostBack="True" ontextchanged="TextBox1_TextChanged"></asp:TextBox>