I have a masterpage with a Login Control in it. When the Login button is clicked, I would like for a JQuery Dialog to popup if the user's membership is about to expire within 30 days, else it will just log them in as normal. I can't figure out how to do it. I wll post parts of code:
Here is the javascript:
<script type="text/javascript">
function showjQueryDialog() {
$("#dialog").dialog("open");
}
$(document).ready(function() {
$("#dialog").dialog({
autoOpen: false,
modal: true,
buttons: { "Renew Membership": function()
{ $(this).dialog("close"); } }
});
});
</script>
The login button is called ibtnLoginButton and here is part of the code:
//Grab the user profile.
UserProfiles userProfile =
UserProfiles.GetUserProfiles(txtUserName1.Text);
//Calculate the Time Span
TimeSpan timeSpan = userProfile.Expiration.Subtract(DateTime.Now);
if (timeSpan.Days < 30)
{
//Show JQuery Dialog Here
}
else
{
//Continue with Login Process.
}
-
Why not always call the jquery method when the button is clicked, and then determine within the javascript method whether or not you want to show the dialogue? If not, just don't do anything. Since you're just checking whether ExpirationDate is smaller than now + 30 days, you can do that calculation just fine in javascript.
Edit:
I can't provide you with the exact solution, but here is some pseudocode to get you on your way.
First make the user profile's expiration date need available in javascript:
<script> var userProfileExpiresOn = "<asp:Literal ID="userProfileExpiresOn" />"; </script>
Then edit your method so that it does the logic you're currently doing server-side for you:
<script> function showjQueryDialog() { if (userProfileExpiresOn < (now + 30 days)) $("#dialog").dialog("open"); } </script>
You can find some documentation on how to work with dates in Javascript at W3schools.
Xaisoft : Can you provide an example? I am new to javascript.Rahul : Updated the answer with a pseudocode example. -
how about this?
if (timeSpan.Days < 30) { //Show JQuery Dialog Here ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "showExpiration", "showjQueryDialog()", true); }
Xaisoft : Ok, I tried this and it is showing the text which is in the div for the dialog, but the dialog is not popping up.SquidScareMe : Try changing the Javascript function showJQueryDialog() to this: function showJQueryDialog(){ alert('Time to renew membership!'); } or something like that. Would that suit your needs?SquidScareMe : Once you get that working you could try getting a nice JQuery modal dialog to appear like this one: http://www.ericmmartin.com/projects/simplemodal/Xaisoft : Ok the alert worked, but my problem is now the dialog does not show. It just shows the contents of the div on the page instead of popping up the JQuery dialogSquidScareMe : This is getting into a JQuery debugging issue which I'm not as familiar with. Are you pointing to the JQuery UI Dialog script? You need to point to that as well at the JQuery library, I believe.SquidScareMe : You can download the JQuery UI here: http://jqueryui.com/downloadXaisoft : Yes, I have got it to work with an asp:button, but I can't figure out how to get it to work based on a condtion such as if user.expiration < 30 days then show the dialog, else log the user in.SquidScareMe : Can you please post the code from the ASP:Button that shows the JQuery dialog? Thanks. -
If, as you've said you've got this jQuery dialog to appear when clicking an asp:Button, why not just hide the button and change your javascript to just press the button once the page has loaded?
0 comments:
Post a Comment