Solved

ModalPopupExtender

Posted on 2010-11-21
13
422 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

864 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

24 Experts available now in Live!

Get 1:1 Help Now