Javascript从后面的代码确认消息 [英] Javascript confirm message from code behind

查看:71
本文介绍了Javascript从后面的代码确认消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



任何人都可以建议我如何写代码后面的确认框

我希望得到回报值得用户点击'确定'还是

'取消',

取决于我需要使用if else进一步处理。

我想传递一个来自数据库的值来确认消息。

for ex:return confirm(10个元素)

消息中的这个10来自数据库

多数民众赞成在使用此代码后面的电话。





提前致谢,

Deepthi

Hi all,

Can anyone suggest me how to write the confirm box in code behind
and i want to get the return value whether the user clicked 'ok' or
'cancel',
Depending on that i need to process further using if else .
"I want to pass one value which is from database to confirm message."
for ex: return confirm(10 elements)
This 10 in the message is getting from database
Thats y i am using this calling from code behind.


Thanks in advance,
Deepthi

推荐答案

hi deepthi,



试试这个会有所帮助;使用AjaxControlToolKit DLL



hi deepthi ,

try this one this will help ; use AjaxControlToolKit DLL

<cc1:ModalPopupExtender ID="MPE"  runat="server" CancelControlID="btnCancel" OkControlID="btnOk"
    TargetControlID="HiddenField1" PopupControlID="MessageDiv" BackgroundCssClass="popupbg">

<asp:HiddenField ID="HiddenField1" runat="server" />
<div  runat="server" id="MessageDiv" class="popupdiv" style="width: 450px; display: none">   
    <table width="100%">
        <tr>
            <td>
                <asp:Label ID="lblMsg" runat="server">
            </td>
        </tr>
        <tr></tr>
        <tr>
            <td align="center">
                <asp:Button ID="btnOK" runat="server" Text="Ok" OnClick="btnOK_Click" />
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
            </td>
        </tr>
    </table>
    <br />   





// -----代码背后



on按钮点击事件

---------------------------



//-----On code behind

on button click event
---------------------------

lblMsg.Text ="Your Message";
MPE.Show();


如果我理解,你需要在你的aspx页面中写下

后写

If I understand, You need bellow
in your aspx page write following
<script language="javascript" type="text/javascript">
    function confirmSearch() {
        if (confirm("Are you sure you want to search!"))
            return true;
        return false;
    }
</script>





和按钮执行以下操作





and in Button do the followings

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return confirmSearch()" OnClick="searchfromDate" />





希望有帮助



Hope it help


嘿,



考虑以下代码:

Hey,

Consider the code below :
string messageFromDatabase = "Are you sure you want to do this?";
StringBuilder javaScript = new StringBuilder();
javaScript.Append("<script type=\"text/javascript\">\n");
javaScript.Append("function doConfirm(){\n");
javaScript.Append("\tif (confirm('");
javascript.Append(messageFromDatabase);
javaScript.Append("'){\n");
javaScript.Append("\t\t// code when the user clicks OK\n");
javascript.Append("\t} else {\n");
javaScript.Append("\t\t// code when the user clicks cancel\n");
javascript.Append("\t}\n");
javaScript.Append("}\n");
javaScript.Append("</script>\n");





您可以在 Page_Load() <中将脚本添加到页面中br />



You can add the script to the page in Page_Load()

Page.ClientScript.RegisterClientScriptBlock(typeof(Page),
    "confirmationScript", javaScript.ToString());





希望有所帮助,



干杯,Eduard



Hope it helps,

Cheers, Eduard


这篇关于Javascript从后面的代码确认消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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