Response.Redirect() disables back-button - c#

As far as I understand, Response.Redirect("http://stackoverflow.com"); tells the browser to initiate a request to another URL.
One of the results of this is that the browser "remembers" the redirection, and allows pressing "back."
However, I have a website where Response.Redirect disables the ability to press the browser's "Back" button, as if the browser had opened a new window. (Browsing history is not forgotten, unlike with Server.Transfer.)
The redirection used to work properly in the past, so I suspect the problem has something to do with the IIS server (IIS7).
I apologize in advance if this question should be moved to ServerFault.com.
UPDATES:
Here is some code:
protected void btnClickMe_Click(object sender, EventArgs e)
{
// ...
// some server-side logic
// ...
Response.Redirect("NewPage.aspx?ProductID=" + idNum);
}
Regarding "disables the ability to press the browser's 'Back' button", what I meant is that the button cannot be pressed. Same as when you open a new window. The button is gray, and clicking it has absolutely no effect.
UPDATE 2:
This has been tested with IE6 and IE8.

The problem was NOT with the Response.Redirect();.
When I was on OldPage.aspx, I entered a new URL in the address bar. Once the browser loaded the new site, it disabled the back-button.
Conclusion: There is something wrong with OldPage.aspx, not the redirection to NewPage.aspx.
I still don't know why THIS happens, but this is an entirely different question.

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) //check if the webpage is loaded for the first time.
{
ViewState["PreviousPage"] =
Request.UrlReferrer;//Saves the Previous page url in ViewState
}
}
protected void btnBack_Click(object sender, EventArgs e)
{
if (ViewState["PreviousPage"] != null) //Check if the ViewState
//contains Previous page URL
{
Response.Redirect(ViewState["PreviousPage"].ToString());//Redirect to
//Previous page by retrieving the PreviousPage Url from ViewState.
}
}

Related

Page load captcha not load in webbrowser

I am using webbrowser into Windows application.
When webbrowser navigate first time, there is no problem.
But calling second time webbrowser navigate captcha does not change.
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("uyg.sgk.gov.tr/SgkTescil4a");
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.AllowNavigation = true;
}
To prevent page caching on your client, which may be the reason why you see the Captcha not changing use
webbrowser1.Refresh(WebBrowserRefreshOption.Completely).
to clear the cache. If its not a client side caching issue, then its a problem with the website.

Action when website changes

how can i make action when link in WebBrowser1 changes?
I tried to do if(webbrowser1 == https://www.google.nl/intl/en/about/)but it doesn't work
I mean at startup in WebBrower1 is http://www.google.com and when i click something in this WebBrowser1 link changes, for example https://www.google.nl/intl/en/about/ and my question is, how can make an action (MessageBox.Show("you are here"); when i'm on main google page and i'm go to about page
This is "Windows Forms Application"
I guess you could do it using Navigated event.
You can also find an example and how to catch and redirection moment here: https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.navigated(v=vs.110).aspx
I believe this example will help you:
// Shows ModalWindow upon navigation.
private void webBrowser1_Navigated(object sender,
WebBrowserNavigatedEventArgs e)
{
MessageBox.Show("you are here:" + WebBrowserNavigatedEventArgs.Url);
}

server side click event doesn't fire on LinkButton when PostBackUrl property has been set to another page

I put a linkbutton control named as "Logout" on my webpage with VS 2010.
When users press the "Logout" linkbutton , I want the system to do two things.
First is to trigger a server side click event to do some things such clear all session variables etc..
Second is to redirect to user to another page such logon.aspx
So I wrote following codes
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
LinkButton1.PostBackUrl = "LogOn.aspx";
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Session.Abandon();
....
....
}
But when the programs runs , any user clicks the linkbutton.The codes of LinkButton1_Click never be executed, because the page has already been redirect to Logon.aspx page and never do the LinkButton1_Click()
My Question is why LinkButton1 offers PostBackUrl property and server-side click event , but it seems that they don't cooperate very well ~
This is because by setting the PostBackUrl you are saying that when the button is clicked that you want it to post to the LogOn.aspx page rather than posting back to itself. Since you are posting to LogOn.aspx you will never trigger the event.
Instead, you should use some type of redirect in your button click after your sesion.abandon.
Can you check if there's an event LinkButton1_Click subscribed to a LinkButton1's OnClick?
Then for your second concern since you're referring with ASP.Net, you can handle this with your Global.asax, where you will redirect any user to a login page every time session was destroyed. See reference links below:
1.) SessionStateModule.End Event
2.) Using Session in Global.asax

Opening Web Browser click in default browser

Currently I am building a windows form app using c#. I have a web browser control on my form that displays a google ad. When clicked the webpage is displayed within the little 300x300 web browser control on the form. Is there a way for me to launch the default browser when the ad is clicked instead?
Thanks.
Edit: I figured out I can do so open the default browser by using Process.Start("url here"); but the browser windows is opening upon app load.
Edit Adding Code:
Form.cs
private void AdPanelNavigating(object sender, WebBrowserNavigatingEventArgs e)
{
e.Cancel = true;
if (e.Url != null ) Process.Start(e.Url.ToString());
}
Form.Designer.cs
this.AdPanel.Navigating += new WebBrowserNavigatingEventHandler(AdPanelNavigating);
You can add Navigating event handler:
webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(WebBrowser_Navigating);
void WebBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e) {
e.Cancel = true;
Process.Start(e.Url);
}
It will open default browser instead of opening this url inside webbrowser.

Show and Hide Modal Popup Extender Not working

Hi all I have a modal popup extender set to a hidden linkbutton. So when I want to use it I am doing
protected void ProcessFileBtn_OnClick(object sender, EventArgs e)
{
WaitModalPopupExtender.Show();
//DO STUFF
WaitModalPopupExtender.Hide();
}
Process takes a while, but no Modal Pop Up extender shows, when I create a button just to do the show function it works, but when I add in this
protected void Test_Click(object sender, EventArgs e)
{
WaitModalPopupExtender.Show();
System.Threading.Thread.Sleep(5000);
WaitModalPopupExtender.Hide();
}
Nothing shows up. Any thoughts?
It won't work.
Why...??
First request sent to Server.
WaitModalPopupExtender.Show();----Executed---But no response send to Client
System.Threading.Thread.Sleep(5000);----Executed---But no response send to Client
WaitModalPopupExtender.Hide();----Executed---Now its time to send the response
Now you can expect the output that will be sent to the Client
Without seeing all of the code it's hard to tell, but I believe that the page is doing a PostBack when you click the linkbutton. When the page does a postback, it refreshes and therefore your ModalPopupExtender won't show. I think you're looking for and Ajax call to do what you want, which I'm pretty sure is showing a wait window while processing data.

Categories

Resources