Force PostBack

  • Thread starter Thread starter Amirallia
  • Start date Start date
A

Amirallia

Hello

I want to force the Page.IsPostBack to false when I click an
"asp:button"

Is it possible ?
 
Why ? Telling us the final goal could lead to better suggestions than trying
to fool the ASP.NET infrastructure.

Patrice
 
If you wish to view the page as it was on the first hit, then a
Response.Redirect(this.ResolveUrl(Request.Url.AbsolutePath)); should do it
for you.

MattC
 
I don't know why you want to do that but here is how you can override a
method (of the Page class) that will set the IsPostback to false-

protected override System.Collections.Specialized.NameValueCollection
DeterminePostBackMode()

{

//return base.DeterminePostBackMode ();

return null;

}

Page.DeterminePostBackMode Method [C#]
See Also
Page Class | Page Members | System.Web.UI Namespace | HttpContext | Page
Members (Visual J# Syntax) | Managed Extensions for C++ Programming

Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

Language
a.. C#

b.. C++

c.. JScript

d.. Visual Basic

e.. Show All
Determines the type of request made for the Page class.

[Visual Basic]
Protected Overridable Function DeterminePostBackMode() As _
NameValueCollection
[C#]
protected virtual NameValueCollection DeterminePostBackMode();
[C++]
protected: virtual NameValueCollection* DeterminePostBackMode();
[JScript]
protected function DeterminePostBackMode() : NameValueCollection;
Return Value
If the post back used the POST method, the form information is returned from
the Context object. If the postback used the GET method, the query string
information is returned. If the page is being requested for the first time,
a null reference (Nothing in Visual Basic) is returned.

Remarks
This information is based on whether the page was posted back and whether
the GET or POST HTTP method was used for the request.
 
Il se trouve que Patrice a formulé :
Why ? Telling us the final goal could lead to better suggestions than trying
to fool the ASP.NET infrastructure.

Patrice

ok

I fill a datagrid with data and in one column I have a checkbox
(TemplateColumn).
In the DataGrid1_ItemDataBound event, I set the checkbox visible or not
depending of some conditions.

In this same page I have a button to clear a textbox : here is the code
on the button_click :Me.TextBox1.Text = ""

When I click on this button, the textbox is cleared and my datagrid
shows all the checkbox in the column, so it doesn't execute the
ItemDataBound event.

I write this in the page_load event :
If Not Page.IsPostBack Then
.........
fill my datagrid
end if

When I click on my button, the Page.IsPostBack is true so I don't fill
my datagrid and not event ItemDataBound fired
 
MattC a émis l'idée suivante :
If you wish to view the page as it was on the first hit, then a
Response.Redirect(this.ResolveUrl(Request.Url.AbsolutePath)); should do it
for you.

MattC

Your solution is ok fro all the page, but I only want to fix a colum in
a datagrid, not all the page

Any another idea ?
 
The ItemDataBound event will not fire as the grid is not having new data
added to it, it is simply having its viewstate repopulated. To get your
event to fire each time around you would need to bind the grid each time.
Move it out of the
If Not Page.IsPostBack block.

MattC
 
Possible options would be :
- if you want to rebind on postback just suppress the test ?????!!! instead
of fooling ASP.NET ???
- you could also have the checkbox computation outside of this event. It
would allow to recompute the textobx wihtout binding the grid again
- you could also add a new column in your datasource to achieve the same
result...

Patrice

--
 
One time I wanted to modify the value of page.ispostback, but some people out
here rightly convinced me it was a horrible idea due to lack of understanding
of asp.net.

I'm not sure I understand your requirements, but you might also consider
ItemCreated. ItemCreated fires *every* time each row in the datagrid is
created, whether via databinding or restore from viewstate after postback,
whereas ItemDataBound is only fired when you explicitly call .databind.

Bill
 
Back
Top