使用asp.net web应用程序中的以下消息框。现在我想将此消息框转换为确认消息框并在其为真时执行其他操作否则意味着拒绝该应用程序。
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "<script language='javascript'>alert('Are you sure, you want to apply?');</script>", false);
答案 0 :(得分:6)
我认为你这是错误的做法。您应该在发回之前显示此确认,然后只有在他们选择“应用”时才会回发。
使用ASP.NET Web控件,Button
控件具有OnClientClick
属性,可用于在Http POST之前调用javascript:
你可以这样做:
<asp:button id="btn"
runat="server"
Text="Apply"
OnClientClick="return confirm('Are you sure you wish to apply?');"
OnClick="btn_Click" />
答案 1 :(得分:2)
注册脚本而不是警告
<script type="text/javascript">
var r=confirm("Are you sure you are sure?")
if (r==true)
{
//You pressed OK!
}
else
{
//You pressed Cancel!
}
</script>
答案 2 :(得分:0)
相当于确认框的javascript是confirm()方法。此方法返回true或false值,具体取决于用户的“OK”或“Cancel”按钮响应。
<强>用法:强>
var confirmed = confirm('Are you sure?','Are you sure you want to delete this item?');
if(confirmed){
//do something
} else {
//do something else
}
答案 3 :(得分:0)
试试这个
在您的cs文件中添加此内容,以显示confirm
而不是alert
string confirm =
"if(confirm('Are you surely want to do this ??')) __doPostBack('', 'confirmed');";
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", confirm, true);
在同一页面上添加此项以检查用户何时来自该确认框
protected void Page_Load(object sender, EventArgs e)
{
string parameter = Request["__EVENTARGUMENT"];
if (string.Equals("confirmed",
parameter,
StringComparison.InvariantCultureIgnoreCase))
{
// Call your server side method here
}
}
为此,我使用了__doPostBack
,您可以从here了解更多信息。
希望它能帮助你
答案 4 :(得分:0)
当用户点击按钮
时,尝试对OnClientClick
事件进行此代码检查
<script type="text/javascript">
function check()
{
var chk =confirm("Are you sure you are sure?")
if (chk==true)
{
// try you want
}
else
{
// try you do not want
}
return true;
}
</script>
<asp:button id="Button1"
runat="server"
Text="Button1"
OnClientClick="return check();"/>
答案 5 :(得分:0)
private void showMessage(string msg){
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "<script language='javascript'>alert('"+ msg +"');</script>", false);
protected void BtnReg_Click(object sender,EventArgs e) {
OracleHelper.OracleDBOpen();
object flag = OracleHelper.OracleExecuteScalar("your select Query ");
if (flag == null)
{
showMessage("Failed !!! ");
}
else
{
string reg = String.Format("your Insert Query ");
showMessage("successfuly");
OracleHelper.OracleExecuteNonQuery(reg);
}
OracleHelper.OracleDBClose();
}
}
答案 6 :(得分:0)
要在C#中完全执行此操作,您可以尝试:
protected override void OnInit(EventArgs e)
{
AddConfirmationButton();
base.OnInit(e);
}
private void AddConfirmationButton()
{
Button confirmButton = new Button();
confirmButton.Text = "Action Foo";
string confirmationMessage = "Are you sure you wish to do action Foo?";
confirmButton.OnClientClick = "return confirm('" + confirmationMessage + "');";
confirmButton.Command += confirmButton_Command;
Controls.Add(confirmButton);
}
void confirmationMessage_Command(object sender, CommandEventArgs e)
{
DoActionFoo(); //work your magic here.
}
这将从网页向用户显示“确定/取消”对话框。如果用户单击“确定”,则命令“事件”中的函数将触发。如果用户点击“取消”,则不会发生任何事情。
答案 7 :(得分:0)
ScriptManager.RegisterStartupScript(page,this.GetType(), "temp","javascript:calopen();
",true);
function calopen()
{
if (confirm("Are you sure?"+'\n'+"Are you want to delete"))
{
enter code here
}
else
{
return false;
}
}