[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

ModalPopupExtender

Posted on 2010-11-21
13
Medium Priority
?
434 Views
Last Modified: 2012-05-10
I'm using a ModalPopupExtender to display a panel and then calling a server-side mtheod from there.  It works great...EXCEPT the form remembers the data entered (OK, so I clear that, no problem) and, if I refresh the page (F5), the server-event gets called again?  Any ideas?


<asp:ModalPopupExtender ID="LinkButton1_ModalPopupExtender" runat="server" DynamicServicePath=""
                                                        Enabled="True" TargetControlID="LinkButton1" PopupControlID="pnlModal" BackgroundCssClass="modalBackground"
                                                        DropShadow="true"  >
                                                    </asp:ModalPopupExtender>
                                                    <asp:Panel ID="pnlModal" runat="server" CssClass="modalPopup" Style="display: none" EnableViewState="false">
                                                        <table>
                                                            <tr>
                                                                <td style="width: 150px">
                                                                    Select Rating:
                                                                </td>
                                                                <td>
                                                                    <asp:Rating ID="rtgSelectRating" runat="server" StarCssClass="ratingStar" FilledStarCssClass="filledRatingStar"
                                                                        EmptyStarCssClass="emptyRatingStar" WaitingStarCssClass="waitingRatingStar" MaxRating="5"
                                                                        ReadOnly="false">
                                                                    </asp:Rating>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    Comments:
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="2">
                                                                    <textarea id="txtComments" cols="40" rows="10" runat="server"></textarea>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="2">
                                                                    <asp:CheckBox ID="chkSubmitAnonymously" runat="server" Text="Submit anonymously" />
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    <br />
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    <asp:Button ID="btnSubmitRating" runat="server" Text="Submit" OnClick="SubmitRating_Click"  />
                                                                </td>
                                                                <td>
                                                                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </asp:Panel>
0
Comment
Question by:ratdog033
[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
  • 7
  • 6
13 Comments
 
LVL 21

Expert Comment

by:Alfred A.
ID: 34185034
It looks like your LinkButton1 click event is being triggered when a refresh/postback occurs, causing your modal popup to trigger again and thereby triggering your server-event.  
0
 
LVL 2

Author Comment

by:ratdog033
ID: 34185048
I'm sorry, Im not sure I'm following.  Would you break that down a bit with a suggestion on how to correct it?
0
 
LVL 21

Expert Comment

by:Alfred A.
ID: 34185068
OK.  Can you provide a code snippet of your code behind especially the point where the modal popup is triggered if possible?

What I was saying is that it looks like something in your code-behind is triggering your LinkButton1 (the one in your TargetControlID in the modal popup).  It would help us to clear this out if you could provide some code snippet if possible.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Author Comment

by:ratdog033
ID: 34185078
this is all I have in the code behind for these controls:

protected void SubmitRating_Click(object sender, EventArgs e)
        {
            SellerDB sellerDB = new SellerDB();
            string results = "";
            int userId = PortalSecurity.GetUserID();
            int rating = rtgSelectRating.CurrentRating;
            string comments = txtComments.Value;
            bool isAnonymous = chkSubmitAnonymously.Checked;
            bool isSuccess = sellerDB.InsertUpdateVendorRating(
                   sellerID,
                   0,
                   userId,
                   rating,
                   comments,
                   isAnonymous,
                   ref results
                );
}
0
 
LVL 21

Expert Comment

by:Alfred A.
ID: 34185137
OK.  I have a suggestion.  Use an UpdatePanel to control the triggers in your modal popup.  I modified your code below.  Also, when you show or hide the modal popup, do you use Me.LinkButton1_ModalPopupExtender.Show  and  Me.LinkButton1_ModalPopupExtender.Hide?  Also with the UpdatePanel UpdateMode set to "Conditional", you can trigger a partial postback using updPnlModal.Update method.   I hope this helps.


<asp:ModalPopupExtender ID="LinkButton1_ModalPopupExtender" runat="server" DynamicServicePath=""
                                                        Enabled="True" TargetControlID="LinkButton1" PopupControlID="pnlModal" BackgroundCssClass="modalBackground"
                                                        DropShadow="true"  >
                                                    </asp:ModalPopupExtender>
                                                    <asp:Panel ID="pnlModal" runat="server" CssClass="modalPopup" Style="display: none" EnableViewState="false">

                                <asp:UpdatePanel ID="updPnlModal" runat="server" UpdateMode="Conditional">
                                <ContentTemplate>


                                                        <table>
                                                            <tr>
                                                                <td style="width: 150px">
                                                                    Select Rating:
                                                                </td>
                                                                <td>
                                                                    <asp:Rating ID="rtgSelectRating" runat="server" StarCssClass="ratingStar" FilledStarCssClass="filledRatingStar"
                                                                        EmptyStarCssClass="emptyRatingStar" WaitingStarCssClass="waitingRatingStar" MaxRating="5"
                                                                        ReadOnly="false">
                                                                    </asp:Rating>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    Comments:
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="2">
                                                                    <textarea id="txtComments" cols="40" rows="10" runat="server"></textarea>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="2">
                                                                    <asp:CheckBox ID="chkSubmitAnonymously" runat="server" Text="Submit anonymously" />
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    <br />
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    <asp:Button ID="btnSubmitRating" runat="server" Text="Submit" OnClick="SubmitRating_Click"  />
                                                                </td>
                                                                <td>
                                                                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                                                                </td>
                                                            </tr>
                                                        </table>

                                    </ContentTemplate>
                                    </asp:UpdatePanel>

                                                    </asp:Panel>

Open in new window

0
 
LVL 2

Author Comment

by:ratdog033
ID: 34185298
Thank you for the suggestions.  I'll get to this sometime tomorrow and let you know how it goes.
0
 
LVL 2

Author Comment

by:ratdog033
ID: 34187881
I've tried your code as suggested, but the method SubmitRating_Click still fires on page refresh.  It's as if the script is being called from page load...

I'm not explicity calling the modal popup Show and Hide methods.
0
 
LVL 21

Accepted Solution

by:
Alfred A. earned 1500 total points
ID: 34188181
OK.  Try modifying the UseSubmitBehavior of your Button Control to "False" and test it out.

<asp:Button ID="btnSubmitRating" runat="server" Text="Submit" OnClick="SubmitRating_Click" UseSubmitBehavior="False"  />

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.usesubmitbehavior.aspx



0
 
LVL 2

Author Comment

by:ratdog033
ID: 34191405
Thank you.  That didn't work for me either.
0
 
LVL 21

Expert Comment

by:Alfred A.
ID: 34193391
By the way, Is btnSubmitRating the OK button in your ModalPopupExtender?  If this is the case you should set the OKControlID property to this button.

Check the following references in using a ModalPopupExtender.  This might help.

http://www.asp.net/ajax/videos/how-do-i-use-the-aspnet-ajax-modalpopup-extender-control

http://www.ajaxtutorials.com/ajax-tutorials/using-modalpopupextender-from-ajax-control-toolkit-c/

http://www.asp.net/ajax/ajaxcontroltoolkit/samples/modalpopup/modalpopup.aspx

http://www.karpach.com/ModalPopupExtender-Example.htm
0
 
LVL 21

Expert Comment

by:Alfred A.
ID: 34193418
0
 
LVL 2

Author Closing Comment

by:ratdog033
ID: 34193602
I ended up needing to refresh the base page after submit, so I explicity call a Response.Redirect to itself.  This fixed the problem.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

650 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