locked
Response.Redirect(Request.RawUrl) in vb.net RRS feed

  • Question

  • User-1578974752 posted

    In page load, Button.text is YES

    In button click event, I used

    Button.text ="NO"

    Response.Redirect(Request.RawUrl)

    I want the text of a button to change in to "NO" form YES, Once the button is clicked.

    Now it is not happening as the Response.Redirect(Request.RawUrl) is going through the  page load again. How can I solve this. Appreciate the Help

    Thursday, February 7, 2019 6:16 AM

All replies

  • User753101303 posted

    Hi,

    Just delete this Response.Redirect(Request.RawUrl). You are showing the same page again but with a GET again putting the page to its initial state. Just let the POST to happen and show the page again.

    Thursday, February 7, 2019 9:01 AM
  • User-1578974752 posted

    If I didn't place Response.Redirect(Request.RawUrl), then ,Status of the form is not changing upon clicking Submit.

    Once submit clicked some functions are happening and the Status of Form is changing in to Pending. Response.Redirect(Request.RawUrl) helps me to show the updated status of the form.

    Thursday, February 7, 2019 9:32 AM
  • User475983607 posted

    In page load, Button.text is YES

    In button click event, I used

    Button.text ="NO"

    Response.Redirect(Request.RawUrl)

    I want the text of a button to change in to "NO" form YES, Once the button is clicked.

    Now it is not happening as the Response.Redirect(Request.RawUrl) is going through the  page load again. How can I solve this. Appreciate the Help

    This is pretty basic stuff...  simply send a query string value in the URL.

    Response.Redirect(Request.RawUrl & "?buttonText=No") 

    Read the value in the Page_Load and set the button text.

    Dim ButtonText As String = Request.QueryString("buttonText")
    theButton.Text = ButtonText 

    I recommend learning ASP.NET state management fundamentals.

    Thursday, February 7, 2019 1:50 PM
  • User753101303 posted

    Using redirect causes the page to be shown with a GET request and is precisely intended to show the page again using its "default" state.

    What if I close the browser and come on the same page tomorrow ? The button should be still "YES" ? If confirmed it seems "NO" should not be the initial value for this button but depends rather on some data found inside your db...

    Thursday, February 7, 2019 2:07 PM
  • User-1174608757 posted

    Hi shsu,

    According to your description, If you use Response. redirect, the program will just do the page redirect first,so there is nothing  changed to button. To realize your requirement, I suggest you to use window.location in code behind.Here is the demo , I hope it could help you.

    Aspx:

    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Button ID="Button1" runat="server" Text="NO" OnClick="Button1_Click" />
            </div>
        </form>
    </body>
    </html>

    aspx.vb

    Public Class WebForm1
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Protected Sub Button1_Click(sender As Object, e As EventArgs)
            Button1.Text = "Yes"
            ClientScript.RegisterStartupScript(Me.GetType(), " ", "window.location.replace('Default.aspx')", True)
        End Sub
    End Class

    It shows as below:

    Best Regards

    Wei Zhang

    Friday, February 8, 2019 2:30 AM