Solved

AJAX ToolKit Modal Box and LinkButton

Posted on 2009-04-03
9
592 Views
Last Modified: 2012-05-06
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
Comment
Question by:steverguy
  • 5
  • 4
9 Comments
 
LVL 18

Expert Comment

by:David Robitaille
ID: 24063540
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
 
LVL 18

Expert Comment

by:David Robitaille
ID: 24063963
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
 
LVL 1

Author Comment

by:steverguy
ID: 24064038
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:steverguy
ID: 24064079
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
 
LVL 18

Accepted Solution

by:
David Robitaille earned 500 total points
ID: 24064128
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
 
LVL 1

Author Comment

by:steverguy
ID: 24064272
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
 
LVL 18

Expert Comment

by:David Robitaille
ID: 24064297
you should probably do something like this to retrive the hidden control...
document.getElementById("<%=catid.ClientID%>").value= catid
(like for zip code....)

0
 
LVL 1

Author Comment

by:steverguy
ID: 24064302
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
 
LVL 18

Expert Comment

by:David Robitaille
ID: 24064318
Glad i could help!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question