1

I have a Page which has a Control on it with 2 textboxes (username and password) and an asp:Button. If the user's membership is going to expire within 30 days and the button is clicked, I want the JQuery dialog to popup. Inside the JQuery dialog, I have some text and an asp:LinkButton. The link button has an event attached to it, but it is not being fired when I click it in the dialog box. Here is the script tags for the JQuery:

<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="ui.core.js"></script>
<script type="text/javascript" src="ui.draggable.js"></script>
<script type="text/javascript" src="ui.resizable.js"></script>
<script type="text/javascript" src="ui.dialog.js"></script>

Here is the script the dialog: For testing, I am closing the dialog on Renew Membership click, but I actually want it to fire a method I create in asp.net to direct the user to a another page and pass a session variable.

<script type="text/javascript">
    $(document).ready(function() {
        $("#dialog").dialog({
         // autoOpen: false,
            modal: true,
            buttons: { "Renew Membership": function() { $(this).dialog("close"); } }
        });
    });
</script>

<asp:Content ID="mainContent" runat="server" ContentPlaceHolderID="Content">
<div id="dialog" title="Membership Renewal">
    <p>Uh Oh! Your membership is going to expire.</p><br />
    <p>Hurry up and renew today!</p><br />
    <asp:LinkButton runat="server" Text="Click Here to Renew" 
        onclick="Unnamed2_Click"></asp:LinkButton>
</div>

Here is the click event for the LinkButton:

protected void Unnamed2_Click(object sender, EventArgs e)
{
    UserProfiles userProfile = (UserProfiles)Session["userProfile"];
    Response.Redirect("~/Renew.aspx");
}

What should happen is that when the user clicks the sign-in button, it should popup up the dialog only if the days they have left to expire is <= 30 and if they do, they have the option of clicking the link in the dialog and going to a renew page where I want to pass it a Session variable with a Profile, but that is not being called, so I guess, I would like to know is how can I add the event handler of the button to the dialog and is there a way to set it so that it only comes up once, for example adding a cookie to the users browser and only showing it if they don't have a cookie set.

1
  • I updated my post to include the 30 expiration Commented Mar 19, 2009 at 20:34

1 Answer 1

1

I believe this is more of an ASP.NET issue and not a jQuery dialog issue.

I wouldn't use the onClick and PostBackUrl within the same LinkButton. So, take off the PostBackUrl attribute and instead use

protected void Unnamed2_Click(object sender, EventArgs e){
    UserProfiles userProfile = (UserProfiles)Session["userProfile"];
    Response.Redirect("~/Renew.aspx");
}

If you only need to show the control when the user is > 30 days. I would create a user control.

jquery.renewDialog.js

$(document).ready(function() {
    $("#dialog").dialog({
        modal: true
    });
});

RenewalUserControl.ascx

<asp:ScriptManager runat="server" id="ScriptManager1">
  <Scripts>
    <asp:ScriptReference Path="jquery.renewDialog.js" />
  </Scripts>
</asp:ScriptManager>
<div id="dialog" title="Membership Renewal">
    <p>Uh Oh! Your membership is going to expire.</p><br />
    <p>Hurry up and renew today!</p><br />
    <asp:LinkButton runat="server" Text="Click Here to Renew" 
        onclick="Unnamed2_Click" />
</div>

Login.aspx

<uc1:RenewalUserControl runat="server" ID="RenewalUserControl1" Visible="false" />

Login.aspx.cs

if (user.IsExpired)
{
  RenewalUserControl1.Visible = true;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Ok, I removed the PostBackUrl and now it is redirected to the page correctly. Now, I set the autoOpen to false in the dialog and I want an asp:button which is located in a control to fire the dialog only if the users expiration is less than or equal to 30 days.
Correct me If I am wrong? You are encapsulating the JQuery dialog in a user control and setting it to visible when the user expiration is <= 30 days. Does the dialog popup only when the Renew Control is shown and what if you don't want it to popup everytime.
Yea the beauty here is that if the user control isn't visible the jquery and the dialog shell aren't written out to the html at all.

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.