Solved

AJAX ToolKit Modal Box and LinkButton

Posted on 2009-04-03
9
591 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now