Solved

ModalPopupExtender

Posted on 2010-11-21
13
425 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
  • 7
  • 6
13 Comments
 
LVL 21

Expert Comment

by:Alfred1
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:Alfred1
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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:Alfred1
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 21

Expert Comment

by:Alfred1
ID: 34185153
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:
Alfred1 earned 500 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:Alfred1
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:Alfred1
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 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

9 Experts available now in Live!

Get 1:1 Help Now