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.
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.
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...
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.
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
Member
129 Points
277 Posts
Response.Redirect(Request.RawUrl) in vb.net
Feb 07, 2019 06:16 AM|shsu|LINK
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
All-Star
43250 Points
14982 Posts
Re: Response.Redirect(Request.RawUrl) in vb.net
Feb 07, 2019 09:01 AM|PatriceSc|LINK
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.
Member
129 Points
277 Posts
Re: Response.Redirect(Request.RawUrl) in vb.net
Feb 07, 2019 09:32 AM|shsu|LINK
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.
All-Star
37161 Points
15015 Posts
Re: Response.Redirect(Request.RawUrl) in vb.net
Feb 07, 2019 01:50 PM|mgebhard|LINK
This is pretty basic stuff... simply send a query string value in the URL.
Read the value in the Page_Load and set the button text.
I recommend learning ASP.NET state management fundamentals.
All-Star
43250 Points
14982 Posts
Re: Response.Redirect(Request.RawUrl) in vb.net
Feb 07, 2019 02:07 PM|PatriceSc|LINK
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...
Member
420 Points
197 Posts
Re: Response.Redirect(Request.RawUrl) in vb.net
Feb 08, 2019 02:30 AM|Wei Zhang|LINK
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:
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