How can I stop asp.net from re-appending querystrings on form post back?

2k views Asked by At

I am developing a simple rating system for my employer's profile based web-app. Here is my problem:

  • The actual page is domain.com/review.aspx?user=username, but I use the url-rewrite module in IIS to use domain.com/username/review
  • The page contains a repeater control that displays reviews for that username, as well as a form for people to create new reviews
  • When the form is submitted, asp.net re-appends the (hidden) querystring to the url on postback.
  • The post-back url is now domian.com/username/review?user=username&review, causing the page to break if refreshed.

Is there any way to keep asp.net from re-appending the querystrings that are actually already present, but re-written with IIS

Live link <- submit a review, and then refresh the page (edit) by clicking in the address bar! Beautiful yellow error message.

EDIT

C# code:

protected void submitReview(object sender, EventArgs e)
    {
        try
        {
            int starRating = txtStarRating.Text == "" ? 0 : Int32.Parse(txtStarRating.Text);
            testimonials.addNew(Int32.Parse(txtHiddenUid.Text), reviewContent.Text, reviewerName.Text, true, starRating);
            reviewForm.Visible = false; pnlReviewSubmissionSuccess.Visible = true;
        }
        catch { starErrorMessage.Text = "There was an error submitting your review. Please refresh this page and try again."; }
    }

ASP code:

<div ID="pnlSubmitReview" runat="server">
                <div id="reviewForm" runat="server">
                    <div id="leaveReviewBoxes">
                        <span style="margin-bottom:10px; float:left; font-weight:bold;">Leave a Review</span>
                        <div style="clear:both;"></div>
                        <asp:Label ID="nameLabel" runat="server">Name:</asp:Label>            
                        <asp:Textbox runat="server" ID="reviewerName"></asp:Textbox>
                        <div style="clear:both;"></div>
                        <asp:Label ID="reviewLabel" runat="server">Review:</asp:Label>
                        <asp:Textbox runat="server" ID="reviewContent" Width="200px" TextMode="MultiLine"></asp:Textbox>
                    </div>

                    <div>
                        <ol id="starlist"> 
                            <li><a id="star1" name="star1" href="javascript:void(0)" class="star"></a></li>
                            <li><a id="star2" name="star2" href="javascript:void(0)" class="star"></a></li>
                            <li><a id="star3" name="star3" href="javascript:void(0)" class="star"></a></li>
                            <li><a id="star4" name="star4" href="javascript:void(0)" class="star"></a></li>
                            <li><a id="star5" name="star5" href="javascript:void(0)" class="star"></a></li>
                        </ol>
                        <asp:TextBox ID="txtStarRating" runat="server" Text=""></asp:TextBox>            
                        <asp:Label runat="server" ID="starErrorMessage"></asp:Label>
                        <asp:TextBox ID="txtHiddenUid" runat="server" Visible="false"></asp:TextBox>
                    </div>
                    <asp:Button runat="server" ID="submitReviewButton" Text="Submit Review" OnClick="submitReview" />
                </div>

                <div ID="pnlReviewSubmissionSuccess" runat="server" Visible="false">
                        Thank you! Your review has been submitted.
                </div>
            </div>
1

There are 1 answers

1
Shawn On BEST ANSWER

I believe you need to set the Page's Form.Action property to the same remapped URL.