我在網上搜索了一段時間,試圖弄清楚如何從代碼隱藏中動態顯示jQuery對話框,到目前爲止我還沒有多少運氣。如何從代碼隱藏中顯示jquery對話
我想在用戶完成註冊我的網站後點擊「創建用戶」按鈕彈出jquery對話框。我只想讓對話框彈出「謝謝你註冊!」如果用戶輸入的用戶名不存在於數據庫中。
這是我有和不工作。我可以使用jQuery與其他東西,除了這一個任務。任何幫助?非常感謝!背後
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblError" ForeColor="Red" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CreateUserButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<script type="text/javascript">
$(function() {
initializedialog();
});
function initializedialog() {
$("#dialog").dialog({
autoOpen: false,
hide: 'blind',
minHeight: 125,
maxWidth: 300,
show: 'blind',
title: 'Thanks!'
});
}
//This function is called from the script injected from code-behind.
function showDialog(message) {
$("#dialog").remove();
$("#dialog").append(message);
$("#dialog").dialog('open');
}
</script>
<div id="pnlpopup">
<p class="submitButton">
<asp:Button ID="CreateUserButton" runat="server" CommandName="MoveNext" Text="Create User"
OnClick="CreateUserButton_Click"
ValidationGroup="RegisterUserValidationGroup" SkinID="btnLoginRegister"
Height="29px" Width="107px" />
</p>
</div>
<div id="dialog" style="display: none">
<asp:Label ID="lblMessage" runat="server" Text="Thank you registering!">
</asp:Label>
</div>
代碼:
protected void CreateUserButton_Click(object sender, EventArgs e)
{
bool bStatus = false;
DataTable dt = new DataTable();
string strRedirect = "";
DataRow dr = null;
//retrieve userInput fields
string stringUserName = UserName.Text;
string stringPassword = Password.Text;
string stringConfirmPassword = ConfirmPassword.Text;
//set database user role to default
string userRole = "db_datawriter";
//check if username already exists in database
dr = Data_Access_Management.DataAccess.GetUser(stringUserName);
if (dr != null) // Check if the DataRow returns any data from database
{
lblError.Text = "That Username already exists.";
bStatus = true;
}
if (!bStatus)
{
//insert user into user table in database
Data_Access_Management.DataAccess.InsertUser(stringUserName, stringPassword, userRole);
strRedirect = CommonStrings.SessionLoginPage;
//string script = "$('#dialog').dialog('open');";
//ClientScript.RegisterStartupScript(GetType(), "alert('foo');", script, true);
StringBuilder sb = new StringBuilder();
string script = "$(function(){initializedialog();showDialog(\"" + sb.ToString() + "\");});";
ScriptManager.RegisterStartupScript(this, this.Page.GetType(), "dialog", script, true);
//redirect to contact.aspx
Response.Redirect(strRedirect);
}
}
你有錯誤嗎?如果有的話,它說什麼?另外,$(「#dialog」)多次使用? – shanabus 2012-03-02 18:52:43
我剛剛檢查了IE開發人員工具,並在$(function(){ initializedialog(); })中出現「對象預期」錯誤; – jre247 2012-03-02 19:25:18
我也沒有多次使用$(「#dialog」) – jre247 2012-03-02 19:26:42