1

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.
}

3 Answers 3

2

how about this?

if (timeSpan.Days < 30)
{
 //Show JQuery Dialog Here
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "showExpiration", "showjQueryDialog()", true);
}
Sign up to request clarification or add additional context in comments.

7 Comments

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.
Try changing the Javascript function showJQueryDialog() to this: function showJQueryDialog(){ alert('Time to renew membership!'); } or something like that. Would that suit your needs?
Once you get that working you could try getting a nice JQuery modal dialog to appear like this one: ericmmartin.com/projects/simplemodal
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 dialog
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.
|
0

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?

Comments

0

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.

1 Comment

Can you provide an example? I am new to javascript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.