Javascript 需要在asp.net回发逻辑期间发出jQuery确认消息

Javascript 需要在asp.net回发逻辑期间发出jQuery确认消息,javascript,jquery,asp.net,modal-dialog,confirm,Javascript,Jquery,Asp.net,Modal Dialog,Confirm,我在ASP.Net中有一个“注册”类型的Web表单。当用户单击“提交”按钮时,Page.IsPostBack代码更新数据库并“通知用户”将重定向到登录页面。这一切工作正常,但相当丑陋,我想让它更“优雅”。以下是我当前技术的一个片段,摘自Page_Load(IsPostBack): Dim包装器作为新的StringBuilder 作为新的StringBuilder使内部变暗 inner.Append(“公司ID”)'txtCompanyID inner.Append(Convert.ToStrin

我在ASP.Net中有一个“注册”类型的Web表单。当用户单击“提交”按钮时,Page.IsPostBack代码更新数据库并“通知用户”将重定向到登录页面。这一切工作正常,但相当丑陋,我想让它更“优雅”。以下是我当前技术的一个片段,摘自Page_Load(IsPostBack):

Dim包装器作为新的StringBuilder
作为新的StringBuilder使内部变暗
inner.Append(“公司ID”)'txtCompanyID
inner.Append(Convert.ToString(Me.txtCompanyID.Text))
Append(“已成功创建”)
inner.Append(“\n您现在将被重定向,以便您可以第一次登录。”)
包装器。追加(“”)
Append(“window.alert('))
Append(internal.ToString())'将真实消息注入包装器
包装器。追加(“);”)
Append(“window.location.href=”)
Append(“../Login.aspx';”)
包装器。追加(“”)
Response.Write(wrapper.ToString())
我有一点使用jQueryUI对话框作为Javascript更具风格的替代品的经验,但这些对话框是从客户端点击事件调用的,我不知道如何将jQuery注入上述方法中(我怀疑一定有更好的技术,但我就是找不到)


理想情况下,我想要一个样式良好的确认消息,单击OK按钮将用户带到指定的新页面

@gbs-谢谢你的建议。根据这些以及更多的研究和测试,我提出了一个解决方案,我将在这里为像我这样的未来可怜的新手总结:

首先,.aspx中的IsPostBack逻辑简化为构造一条消息,该消息将成为jQuery UI对话框的主要内部内容,并将其传递给新的公共子对话框。因此,OP中的代码如下所示:

Dim inner As New StringBuilder
inner.Append("Success! Your account has been created.<br/><br/>")
inner.Append("A confirmation email message has been sent to you.<br/><br/>")
inner.Append("Just click OK and you will be redirected to <b>Login</b> for the first time.")
UIF.MsgBoxJQUI(inner.ToString(), "TCB Welcomes You", "OK", "../Login.aspx")
//The following function is called from the script injected from code-behind.
function showDialog3(message, title, caption, nextUrl) {
    title = title || 'Welcome to TCB';
    caption = caption || 'OK';
    nextUrl = nextUrl || '../Login.aspx';
    $('body').append("<div id='some-Message'></div>");
    $("#some-Message").dialog({
        autoOpen: false,
        dialogClass: 'myAlert',
        buttons: [
                {
                    text: caption,
                    click: function() {
                        $(this).dialog("close");
                    }
                }
            ],
        create: function() {
            $(this).closest(".ui-dialog").find(".ui-button").eq(1).addClass("deleteButtonClass");
        },
        hide: 'blind',
        height: 'auto',
        width: 'auto',
        close: function(event, ui) { window.location.href = nextUrl; },
        modal: true,
        show: 'blind',
        title: title
    }).dialog('widget')
                .next(".ui-widget-overlay")
                .css("background", "#737373");
    $("#some-Message").append(message);
    $("#some-Message").dialog('open');
    $('.ui-widget-overlay').css('background', '#737373');
}
下一步,我在我的站点布局的头部添加了以下引用。主页面

    <script type="text/javascript" src="<%= ResolveClientUrl("~/js/sitewide.js") %>"></script>

接下来,sitewide.js文件中的实际Javascript函数调用jQuery,如下所示:

Dim inner As New StringBuilder
inner.Append("Success! Your account has been created.<br/><br/>")
inner.Append("A confirmation email message has been sent to you.<br/><br/>")
inner.Append("Just click OK and you will be redirected to <b>Login</b> for the first time.")
UIF.MsgBoxJQUI(inner.ToString(), "TCB Welcomes You", "OK", "../Login.aspx")
//The following function is called from the script injected from code-behind.
function showDialog3(message, title, caption, nextUrl) {
    title = title || 'Welcome to TCB';
    caption = caption || 'OK';
    nextUrl = nextUrl || '../Login.aspx';
    $('body').append("<div id='some-Message'></div>");
    $("#some-Message").dialog({
        autoOpen: false,
        dialogClass: 'myAlert',
        buttons: [
                {
                    text: caption,
                    click: function() {
                        $(this).dialog("close");
                    }
                }
            ],
        create: function() {
            $(this).closest(".ui-dialog").find(".ui-button").eq(1).addClass("deleteButtonClass");
        },
        hide: 'blind',
        height: 'auto',
        width: 'auto',
        close: function(event, ui) { window.location.href = nextUrl; },
        modal: true,
        show: 'blind',
        title: title
    }).dialog('widget')
                .next(".ui-widget-overlay")
                .css("background", "#737373");
    $("#some-Message").append(message);
    $("#some-Message").dialog('open');
    $('.ui-widget-overlay').css('background', '#737373');
}
//从代码隐藏注入的脚本调用以下函数。
函数showDialog3(消息、标题、标题、下一步){
title=title | |“欢迎来到TCB”;
标题=标题| |“好的”;
nextUrl=nextUrl | |'../Login.aspx';
$('body')。追加(“”);
$(“#一些消息”)。对话框({
自动打开:错误,
dialogClass:'myAlert',
按钮:[
{
文字:标题,
单击:函数(){
$(此).dialog(“关闭”);
}
}
],
创建:函数(){
$(this).closest(“.ui对话框”).find(“.ui按钮”).eq(1).addClass(“deleteButtonClass”);
},
隐藏:“瞎子”,
高度:“自动”,
宽度:“自动”,
关闭:函数(事件,ui){window.location.href=nextUrl;},
莫代尔:是的,
节目:“盲人”,
标题:标题
}).dialog(“小部件”)
.next(“.ui小部件覆盖”)
.css(“背景”、“#7373”);
$(“#某些消息”)。附加(消息);
$(“#一些消息”).dialog('open');
$('.ui widget overlay').css('background','#7373');
}
检查此项: