473,379 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

IsPostBack with Response.Redirect to same page

I've got a page that does a search... There is an ImageButton on it that
allows the user to reset the search.

The Click Handler for the button clears out the Data and then redirects to
the same page with Response.Redirect("Search.Aspx", true);

Sometimes the code in Page_Load within the IsPostBack part of the if
statement runs and sometimes it doesn't. IN other words, sometimes
IsPostBack is true and sometimes it is not!

How can I reliably post back to the same page from within an event Handler
and get a fresh post?

I've tried Response.Redirect with both true and false as the second
parameter and Server.Transfer.

One final note, the page in question is the default page for the directory
set via the IIS snapin. (not sure if this is important)

TIA
geo
Nov 18 '05 #1
6 16001
I don't think IsPostBack should ever be true if the page is being hit from a
Response.Redirect. Response.Redirect sends back a HTTP/302 to the browser.
When receiving a HTTP/302 in response to a HTTP POST, a properly behaving
client (e.g. IE) will perform a HTTP GET on the new URL and thus will not
POST the form data to the new page.
How can I reliably post back to the same page from within an event Handler
and get a fresh post?
Rather than using Response.Redirect, why not just have the event handler for
the reset button clear all of the fields?

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.

"DotNetGruven" <ms********@javagruven.com> wrote in message
news:Oc*************@TK2MSFTNGP11.phx.gbl... I've got a page that does a search... There is an ImageButton on it that
allows the user to reset the search.

The Click Handler for the button clears out the Data and then redirects to
the same page with Response.Redirect("Search.Aspx", true);

Sometimes the code in Page_Load within the IsPostBack part of the if
statement runs and sometimes it doesn't. IN other words, sometimes
IsPostBack is true and sometimes it is not!

How can I reliably post back to the same page from within an event Handler
and get a fresh post?

I've tried Response.Redirect with both true and false as the second
parameter and Server.Transfer.

One final note, the page in question is the default page for the directory
set via the IIS snapin. (not sure if this is important)

TIA
geo

Nov 18 '05 #2
Thanks a lot for Eric's informative suggestions.

Hi Geo,

As for using the Response.Redirect, I agree with Eric that this will cause
a new request for the new specified url. So the "IsPostBack" property of
that page should be "false". As you mentioned that the problem page is set
as the "default page" of the certain IIS virtual folder, I do think it is
the potential cause fo the problem. I'm not sure on the detailed codes of
the page and content. But I suggest you tested on a simple clear page:
1. add button and in its click post back event, use response.redirect to
redirect to itself.

2. add breakpoints into the page_load and the click event.

Use F5 debug to trace this page. See whether the IsPostBack property is
always "false" after response.redirect. I always think it should be
"false".

In addition, as Eric has mentioned, why don't you just clear the
dataContents in the button's post back event rather than use
response.redirect?

Please check out the above suggestions. If you have any further questions,
please feel free to post here.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3
I have a similar desire to have Response.Redirect actually cause a
post back. Here is why

private void Page_Load(object sender, System.EventArgs e)
{
LoadContentControl();

if (!Page.IsPostBack)
{
BindTabs();
BindContent();
}
}
The now LoadContentControl() dynamically (this.LoadControl) loads a
specific user control (.ascx) depending on the Selected Tab (which is
stored in a viewstate variable) that i have on the page. By default
(when no tab is orignially selected ie. on a first time visit to the
page) it loads a specified user control. That works great. Now when
someone clicks on one of the tabs a different user control should
load. Effectively, the tab_clicked event fires, the viewstate variable
specifying the different control changes correctly, and that event
calls the LoadContentControl again. The new Control loads fine EXCEPT
that the ViewState is still that for the old control. I know this
because when the user tries to fire an event on the newer user
control, the event isn't caught. However the next time the user tries
to fire an event it works. I assume that this is because the first
time, dynamic user control was loaded after the page load but the
second time it is being loaded in the Page_Load and not after that
phase. So what i suggest is that when the user clicks on a new tab,
the tab event code changes the viewstate variable and asks the page to
reload immidiately, or to reinitialize. Then the correct control would
be loaded early enough to get into the ViewState

Any ideas

Mark
Nov 18 '05 #4
I have a similar desire to have Response.Redirect actually cause a
post back. Here is why

private void Page_Load(object sender, System.EventArgs e)
{
LoadContentControl();

if (!Page.IsPostBack)
{
BindTabs();
BindContent();
}
}
The now LoadContentControl() dynamically (this.LoadControl) loads a
specific user control (.ascx) depending on the Selected Tab (which is
stored in a viewstate variable) that i have on the page. By default
(when no tab is orignially selected ie. on a first time visit to the
page) it loads a specified user control. That works great. Now when
someone clicks on one of the tabs a different user control should
load. Effectively, the tab_clicked event fires, the viewstate variable
specifying the different control changes correctly, and that event
calls the LoadContentControl again. The new Control loads fine EXCEPT
that the ViewState is still that for the old control. I know this
because when the user tries to fire an event on the newer user
control, the event isn't caught. However the next time the user tries
to fire an event it works. I assume that this is because the first
time, dynamic user control was loaded after the page load but the
second time it is being loaded in the Page_Load and not after that
phase. So what i suggest is that when the user clicks on a new tab,
the tab event code changes the viewstate variable and asks the page to
reload immidiately, or to reinitialize. Then the correct control would
be loaded early enough to get into the ViewState

Any ideas

Mark
Nov 18 '05 #5
I have a similar desire to have Response.Redirect actually cause a
post back. Here is why

private void Page_Load(object sender, System.EventArgs e)
{
LoadContentControl();

if (!Page.IsPostBack)
{
BindTabs();
BindContent();
}
}
The now LoadContentControl() dynamically (this.LoadControl) loads a
specific user control (.ascx) depending on the Selected Tab (which is
stored in a viewstate variable) that i have on the page. By default
(when no tab is orignially selected ie. on a first time visit to the
page) it loads a specified user control. That works great. Now when
someone clicks on one of the tabs a different user control should
load. Effectively, the tab_clicked event fires, the viewstate variable
specifying the different control changes correctly, and that event
calls the LoadContentControl again. The new Control loads fine EXCEPT
that the ViewState is still that for the old control. I know this
because when the user tries to fire an event on the newer user
control, the event isn't caught. However the next time the user tries
to fire an event it works. I assume that this is because the first
time, dynamic user control was loaded after the page load but the
second time it is being loaded in the Page_Load and not after that
phase. So what i suggest is that when the user clicks on a new tab,
the tab event code changes the viewstate variable and asks the page to
reload immidiately, or to reinitialize. Then the correct control would
be loaded early enough to get into the ViewState

Any ideas

Mark
Nov 18 '05 #6
I have a similar desire to have Response.Redirect actually cause a
post back. Here is why

private void Page_Load(object sender, System.EventArgs e)
{
LoadContentControl();

if (!Page.IsPostBack)
{
BindTabs();
BindContent();
}
}
The now LoadContentControl() dynamically (this.LoadControl) loads a
specific user control (.ascx) depending on the Selected Tab (which is
stored in a viewstate variable) that i have on the page. By default
(when no tab is orignially selected ie. on a first time visit to the
page) it loads a specified user control. That works great. Now when
someone clicks on one of the tabs a different user control should
load. Effectively, the tab_clicked event fires, the viewstate variable
specifying the different control changes correctly, and that event
calls the LoadContentControl again. The new Control loads fine EXCEPT
that the ViewState is still that for the old control. I know this
because when the user tries to fire an event on the newer user
control, the event isn't caught. However the next time the user tries
to fire an event it works. I assume that this is because the first
time, dynamic user control was loaded after the page load but the
second time it is being loaded in the Page_Load and not after that
phase. So what i suggest is that when the user clicks on a new tab,
the tab event code changes the viewstate variable and asks the page to
reload immidiately, or to reinitialize. Then the correct control would
be loaded early enough to get into the ViewState

Any ideas

Mark
Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Richard N. | last post by:
Hi, I've had a good google and can't find anything already on this so : I'm currently trying to have a 'Page Loading' page on a site. The way things are supposed to work are : page a...
0
by: Geoff Cox | last post by:
Hello, I am trying to get the code below to use formmail-nms.cgi to send the thanks.htm response to the same page using target="_self" but this isn't working - any idea why? Thanks Geoff
2
by: Charlie | last post by:
Hi: I have a button in an .aspx page in banner section of a frameset. It runs a response.redirect to another page. The problem is page loads into active frameset. I would like page to replace...
5
by: darrel | last post by:
I have a 'cancel' button that should reload the current page. Ie, reset the page back to it's initial state. Is the best way to do this to simply have the event handler for that button redirect...
10
by: Johnny Fugazzi | last post by:
I have a couple of pages that have started showing an odd problem. When the code calls Response.Redirect("file.aspx"), nothing happens. The page goes white, and the old URL and querystring are...
4
by: Matt MacDonald | last post by:
Hi everyone, I'm seeing this problem more and more often. Not sure if it's me or IIS or both. Here's the general scenario: I have an ASP.net app that is running and I try to navigate to...
3
by: new214 | last post by:
heya all, ive got abit of a problem. Im doin a system in asp- which works on a test server- but when on moving my application to a development server- it throws the following error messages where I...
5
by: Lupus | last post by:
Hi there! I have some strange behavior in a ASP VB.NET application. I've used response.redirect many times in different pages, and it works like a charm. However in a new page I'm making, the...
3
by: Willy | last post by:
I have a website that uses querystrings on a certain page to show multiple contents. I have created mapped pages to hide the gory details of these querystrings. So instead of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.