Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

ModalPopupExtender

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
ratdog033
Asked:
ratdog033
  • 7
  • 6
1 Solution
 
Alfred A.Commented:
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
 
ratdog033Author Commented:
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
 
Alfred A.Commented:
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
Independent Software Vendors: 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!

 
ratdog033Author Commented:
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
 
Alfred A.Commented:
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
 
ratdog033Author Commented:
Thank you for the suggestions.  I'll get to this sometime tomorrow and let you know how it goes.
0
 
ratdog033Author Commented:
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
 
Alfred A.Commented:
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
 
ratdog033Author Commented:
Thank you.  That didn't work for me either.
0
 
Alfred A.Commented:
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
 
Alfred A.Commented:
0
 
ratdog033Author Commented:
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now