admin管理员组文章数量:1317898
I am trying to raise a Javascript confirm box from code behind.
I am using the following syntax
ScriptManager.RegisterStartupScript(this, GetType(), "key", "javascript:return confirm('Are you sure you want to delete?');", true);
It is throwing an error:
return statement out of function
Please help.
I am trying to raise a Javascript confirm box from code behind.
I am using the following syntax
ScriptManager.RegisterStartupScript(this, GetType(), "key", "javascript:return confirm('Are you sure you want to delete?');", true);
It is throwing an error:
return statement out of function
Please help.
Share Improve this question edited Jul 26, 2013 at 14:56 dda 6,2132 gold badges27 silver badges35 bronze badges asked Jul 26, 2013 at 14:46 Sai AvinashSai Avinash 4,75317 gold badges62 silver badges98 bronze badges1 Answer
Reset to default 6Remove the return
, you are not returning this value anywhere. The RegisterStartupScript
is executing the function in the global context:
ScriptManager.RegisterStartupScript(
this,
GetType(),
"key",
"confirm('Are you sure you want to delete?');",
true
);
But this is probably something you should not even be doing on the server. You should ask for confirmation BEFORE calling the server side. By subscribing to the onclick
javascript handler of the corresponding control that is raising the server side event to delete.
For example if you have a delete link:
<asp:LinkButton
ID="DeleteButton"
runat="server"
CausesValidation="False"
CommandName="Delete"
Text="Delete"
OnClientClick="return confirm('Are you sure you want to delete?');"
/>
本文标签: cRaising Javascript confirm box from code behindStack Overflow
版权声明:本文标题:c# - Raising Javascript confirm box from code behind - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742033590a2416910.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论