如何在代码后面获取javascript确认警报响应 [英] How to get the javascript confirmation alert response in code behind
问题描述
如何从代码后面显示javascript警报并获得对代码隐藏的响应
例如:
if(textbox1.text!=)
{
i需要在此处显示提醒并需要将其响应作为x
if(x == ok)
{
}
else < br $>
{
}
}
< < span class =code-leadattribute> script type = text / javascript >
功能确认( ){
var answer = confirm(你要删除吗?)
if(answer){
document.getElementByID(hdnValue)。value ='true';
}
else {
document.getElementByID(hdnValue)。value ='false';
}
}
< / script >
ScriptManager.RegisterStartupScript(this,typeof(Page),confirm,< script > confirmation(); < / script > ,false);
现在你可以进一步访问hdnValue hiddenField控制值的值。
试试这个js函数: -
function confirmBox(){
if document .getElementById( <%textbox1.ClientID%>)。 value != )
{
var ans = confirm(' 是否要保存此数据?');
if (ans == true ){
return true ;
}
其他 {
return 假跨度>;
}
}
}
参考: -
< a href =http://www.aspsnippets.com/Green/Articles/Server-Side-Code-Behind-Yes-No-Confirmation-Message-Box-in-ASPNet.aspx> http://www.aspsnippets .com / Green / Articles / Server-Side-Code-Behind-Yes-No-Confirmation-Message-Box-in-ASPNet.aspx [ ^ ]
ScriptManager.RegisterStartupScript( this , this .GetType(), redirect,
alert('test 9'); window.location =' +
Request.ApplicationPath + anotherpage.aspx';, true 跨度>);
How to show javascript alert from code behind and get its response to codebehind
eg:
if (textbox1.text !="")
{
i need to show alert here and need to get its response as x
if( x== ok)
{
}
else
{
}
}
<script type="text/javascript"> function confirmation() { var answer = confirm("do you want to delete?") if (answer){ document.getElementByID("hdnValue").value='true'; } else{ document.getElementByID("hdnValue").value='false'; } } </script> ScriptManager.RegisterStartupScript( this, typeof(Page), "confirm", "<script>confirmation();</script>", false);
now you can access the value of hdnValue hiddenField control value further.
try this js function:-
function confirmBox() { if document.getElementById("<%textbox1.ClientID %>").value != "") { var ans = confirm('Do you want to save this data?'); if (ans == true) { return true; } else { return false; } } }
refer:-
http://www.aspsnippets.com/Green/Articles/Server-Side-Code-Behind-Yes-No-Confirmation-Message-Box-in-ASPNet.aspx[^]
ScriptManager.RegisterStartupScript(this,this.GetType(),"redirect", "alert('test 9'); window.location='" + Request.ApplicationPath + "anotherpage.aspx';",true);
这篇关于如何在代码后面获取javascript确认警报响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!