Solved

AJAX ToolKit Modal Box and LinkButton

Posted on 2009-04-03
9
590 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
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: …

746 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

12 Experts available now in Live!

Get 1:1 Help Now