Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 604
  • Last Modified:

AJAX ToolKit Modal Box and LinkButton

Here I am again :)

The problem:  I have a list of categories.  When user clicks a category, if there is no cookie set with their ZipCode, a ModalBox pops up and asks them to enter it.  After they hit ok, the website needs to set the zipcode cookie and proceed to the category page they've chosen.

I, thanks to help from Experts on this site, have gotten some of this to work...

When i start the site, if i click on a category, the modal box appears, i enter the zipcode - and that's pretty much as far as I can get working.

Here's my Javascript:
<script language="javascript" type="text/javascript">
            function whatCategory(catid){  
                if(document.getElementById("<%=ZipCode.ClientID%>").value=="")
                {
                    $find('ModalPopupExtender1').show();
                    return false;
                }else{
                    alert("Here");
                    return true;
                    location.href="http://localhost:53642/website/catpage.aspx";
                }
            ;}
            function closeModal(){
                $find('ModalPopupExtender1').hide();
            }
        </script>

Here's the linkButton code:
<asp:LinkButton ID="lb_Category" runat="server" CssClass="CatNavMain" OnClientClick="javascript:return whatCategory(1);">Category 1</asp:LinkButton>

Here's the ModalBox Info:
Panel:
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none" Width="233px">
                   <p>Please enter your zip code:<br />
                   <asp:TextBox ID="ZipCode" runat="server"></asp:TextBox>
                   <br />
                      <asp:Button ID="OkButton" runat="server" Text="OK" />
                      <asp:Button ID="CancelButton" runat="server" Text="Cancel" />
                   </p>
                </asp:Panel>
Modal Box:
<% If Len(theZip) <> 5 Then%>
    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="ModalPopupExtender1" runat="server" TargetControlID="dummyLink" PopupControlID="Panel1" BackgroundCssClass="modalBackground" DropShadow="true" OkControlID="OkButton" CancelControlID="CancelButton" />
   <% End If%>

- I can't seem to set the cookie after they've entered the Zipcode - and after they click Ok in the modal box, I can't get the site to continue to the page requested.  I've tried setting the cookie using the panel's button control - but this doesn't work.

Any suggestions would be appreciated!


0
steverguy
Asked:
steverguy
  • 5
  • 4
1 Solution
 
David RobitailleAnalyst ProgrammerCommented:
the problem is the OkControlID="OkButton", if "block the postback from the ok button.
http://forums.asp.net/t/1218424.aspx
you could still dismiss the modal pupup by lincking the closeModal javascript function to the onclientclick function..
 
0
 
David RobitailleAnalyst ProgrammerCommented:
did that helped?
  • "can't seem to set the cookie after they've entered the Zipcode - and after they click Ok in the modal box, I can't get the site to continue to the page requested.  I've tried setting the cookie using the panel's button control - but this doesn't work."
you put all your code about the modal popup, but nothing about the cookies. has an exemple, You could use Response.redirect to move to the next page on the code behind (afret the post back).
 
0
 
steverguyAuthor Commented:
that works except for one thing - I loose the value for CatID that is passed to the function by the LinkButton.

For example if someone clicks on the link button for category 1,  - Step 1. I need to track that category id, then step 2. Find out if their ZipCode is entered, Step 3. Go to the next page.  On the next page I need to be able to see what the ZipCode is and what the Category ID is.

So far, I can do Step 1 or Step 2 - but not both.

Thank you for your help!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
steverguyAuthor Commented:
I must have been typing when you posted last.  Here is where i set the cookie - it works now that I have the Modal OK button going to the CodeBehind page:

Protected Sub OkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OkButton.Click
        If Len(ZipCode.Text < 5) Then
            Exit Sub
        Else
            Response.Cookies("ZipCode")("Data") = ZipCode.Text
            Response.Cookies("ZipCode")("Time") = DateTime.Now.ToString("G")
            Response.Cookies("ZipCode").Expires = DateTime.Now.AddMonths(1)
        End If
        ZipCode.Text = ""
    End Sub

If I could just get the value for the CatID into the mix somehow, I think I would be all set - set another cookie and redirect.
0
 
David RobitailleAnalyst ProgrammerCommented:
you coudl use a asp:HiddenField and set it<s value within the whatCategory javascript function, then you will be able to retrive it in the OkButton_Click and set another cookie.
0
 
steverguyAuthor Commented:
That make sense.
I tried this - it didn't work, my javascript might be wrong:

<script language="javascript" type="text/javascript">
            function whatCategory(catid){  
                document.getElementById("hCatID").value= catid
                if(document.getElementById("<%=ZipCode.ClientID%>").value=="")
                {
                    $find('ModalPopupExtender1').show();
                    return false;
                }else{
                    alert("Here");
                    return true;
                    location.href="http://www.michiganweddingplanner.com";
                   
                }
            ;}
            function closeModal(){
                $find('ModalPopupExtender1').hide();
            }
        </script>
0
 
David RobitailleAnalyst ProgrammerCommented:
you should probably do something like this to retrive the hidden control...
document.getElementById("<%=catid.ClientID%>").value= catid
(like for zip code....)

0
 
steverguyAuthor Commented:
I wrote back too soon - i needed this:
document.getElementById("<%=hCatID.ClientID%>").value= catid;

Thanks for your patience and help.  I'm coming from ASP so some of the concepts aren't transfering well.  But we're getting there :)
0
 
David RobitailleAnalyst ProgrammerCommented:
Glad i could help!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now