Solved

ModalPopupExtender

Posted on 2010-11-21
13
419 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

11 Experts available now in Live!

Get 1:1 Help Now