fletchsod
Programmer
- Dec 16, 2002
- 181
I have spend all afternoon trying to make this work. When a customer click the login button, it does the postback to ASP.NET which check for existing user in database. If the user exist then it send the javascript “confirm()” prompt asking yes/no question. The end user then click the javascript yes/no button. I have not figure out how to do a postback with the given yes/no value back to the server as a javascript postback.
I wrote the javascript function below and found that the triggering the ASP.NET button seem to work. But the hidden label value “lblHiddenExistingUserPrompt “ is succesfully returned on the client-side but failed to be returned to the server-side as a postback. :-/ (See variable "sJunk" that contains empty data when a postback was made back to the server)
Is there a way to make this work? (or other way?) There gotta be a way to make this work. (Don't want to make a 2nd webpage and have the customer click the button again.)
Thanks...
I wrote the javascript function below and found that the triggering the ASP.NET button seem to work. But the hidden label value “lblHiddenExistingUserPrompt “ is succesfully returned on the client-side but failed to be returned to the server-side as a postback. :-/ (See variable "sJunk" that contains empty data when a postback was made back to the server)
Code:
string sJunk = Convert.ToString(this.lblHiddenExistingUserPrompt.Text).Trim();
//08/03/2010 - Allow the user to log back in, to retain/discard the session...
if (Convert.ToString(this.lblHiddenExistingUserPrompt.Text).Trim() == "X")
{
sJavaScriptErrorMsg = "";
sJavaScriptErrorMsg += "function ftnExistingUsrAcctLoginPrompt() {\n";
sJavaScriptErrorMsg += " var oLblHiddenExistingUserPrompt = document.getElementById('lblHiddenExistingUserPrompt');\n";
sJavaScriptErrorMsg += " var oBtnLogin = document.getElementById(\"" + this.butLogin.ClientID + "\");\n";
sJavaScriptErrorMsg += " \n";
sJavaScriptErrorMsg += " if (confirm('You did not log out on your last visit. Would you like to resume your previous session or start a new one?')) {\n";
sJavaScriptErrorMsg += " oLblHiddenExistingUserPrompt.value = 'Y';\n";
sJavaScriptErrorMsg += " } else {\n";
sJavaScriptErrorMsg += " oLblHiddenExistingUserPrompt.value = 'N';\n";
sJavaScriptErrorMsg += " }\n";
sJavaScriptErrorMsg += " \n";
sJavaScriptErrorMsg += " oBtnLogin.click();\n";
sJavaScriptErrorMsg += "}\n";
sJavaScriptErrorMsg += "\n";
sJavaScriptErrorMsg += "ftnExistingUsrAcctLoginPrompt();";
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.UpdatePanel1.GetType(), System.Guid.NewGuid().ToString(), sJavaScriptErrorMsg, true);
return; //This exit the function...
}
Code:
<form id="form1" runat="server">
<div>
<!-- ASP.NET AJAX Script Only... -->
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button id="butLogin" runat="server" Text="Log In" EnableViewState="False" onclick="butLogin_Click"></asp:Button>
<asp:Label ID="lblHiddenExistingUserPrompt" runat="server" style="visibility:hidden;"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="butLogin" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
Is there a way to make this work? (or other way?) There gotta be a way to make this work. (Don't want to make a 2nd webpage and have the customer click the button again.)
Thanks...