呼吁code一个确认对话框后面并获得所选择的选项 [英] Calling a confirm dialog box on code behind and get the chosen option

查看:134
本文介绍了呼吁code一个确认对话框后面并获得所选择的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个asp.net应用程序,我需要呼吁code一个确认对话框后面。在这之后,我需要得到用户的点击(如果他在点击OK或取消)。

I'm developing an asp.net application and I need to call a confirm dialog box on the code behind. And after that, I need to get the user's click (if he clicked at OK or Cancel).

如果他点击对话框的OK按钮,我必须继续运行code,我停止前调用对话框。

If he clicked the OK button of the dialog, I must continue to running the code where I stopped before call the dialog.

要解决这个问题,我还以为在放的ASPX类型的按钮输入,并设置它的风格可见性:隐藏。所以,当用户点击OK按钮PROGRAMM会调用这个隐藏按钮,调用将继续停止工作的方法。

To solve this problem I thought in put at the aspx an input of type button, and set it's style to visibility:hide. So, when the users click on the OK button the programm will call this hidden button which calls a method that will continue the job stopped.

我会后我的code,我希望它可以帮助。

I'll post my code, I expect it might help.

在code以下是我的code后面,它调用确认对话框。

The code below is on my code behind, and it calls the confirm dialog.

System.Web.UI.
    ScriptManager.RegisterClientScriptBlock(this, GetType(), "__Mensagem", "if (confirm('" + CustomMessage + "')){document.getElementById(\'<%=btnSave.ClientID%>\').click();}", true); 

在code以下是我的aspx,它的隐藏按钮。

The code below is on my aspx, it's the "hidden" button.

<input style="visibility:hidden;" id="btnSave" runat="server" onclick="btnSave_Click"/>

我不知道为什么不工作。我点击确认对话框中的OK按钮后收到的错误是:埃罗EM节奏去execução就Microsoft JScript中的:的document.getElementById(...)E nulo瓯NAOé微米objeto

I don't know why isn't working. The error that I receive after click on the button OK of the confirm dialog box is the following: Erro em tempo de execução do Microsoft JScript: 'document.getElementByID(...)' é nulo ou não é um objeto

我来自巴西这样的错误是在葡萄牙,翻译英语这件事情是这样的:

I'm from Brazil so the error is in portuguese, a translation to english it's something like this:

我给看看页面的HTML code和我注意到,该按钮是不存在的。

I give a look at the html code of the page and I notice that the button isn't there.

也许这是因为我使用一个UpdatePanel,但是当我删除它(只是为了测试,我必须使用更新面板),同样的错误表现,而在这一次的按钮,分别对页面的HTML code。

Maybe it's because I'm using an UpdatePanel, but when I removed it (just for tests, I must use the Update Panel), the same error is showed, and in this time the button were on the page's html code.

推荐答案

我解决了更换部分问题

document.getElementById(\'<%=btnSave.ClientID%>\').click();

$(\"#ctl00_body_btnSave\").click();

我也被一个asp更换输入元素:按钮

I also replace the input element by an asp:Button.

给看看我的code是怎么对我的code现在背后:

Give a look how my code is on my code behind now:

System.Web.UI.
    ScriptManager.RegisterClientScriptBlock(this, GetType(), "__Mensagem", "if (confirm('" + CustomMessage+ "')){$(\"#" + btnSave.ClientID + "\").click();}", true);

和对我的aspx:

<asp:Button id="btnSave" Width="0px" Text="" runat="server" onclick="btnSave_Click"/>

使用Widht =0像素与文本=不建议隐藏按钮,但我用,因为它不会导致我的问题。它建议使用的CssClass这使得它隐藏。

The use of Widht="0px" and Text="" to hidden the button isn't recommended, but I used because it won't cause me problems. It's recommended the use of a CssClass which make it hide.

因此​​,如果用户确认操作,偶数btnSave_Click称为

So, if the user confirm the operation, the even btnSave_Click is called.

感谢所有的答案。

这篇关于呼吁code一个确认对话框后面并获得所选择的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆