Solved

AJAX ToolKit Modal Box and LinkButton

Posted on 2009-04-03
9
595 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Suggested Courses

738 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