how can i avoid the postback (or ignore it) when not originated by aspecific button

  • Thread starter Thread starter tiago.private
  • Start date Start date
T

tiago.private

Hi everybody,

Imagine the following scenario:
One System.Web.UI.UserControl (UC1) with 2 drop downs and one button
"Filter"
One Webform with (UC1) and a GridView, basically the UC1 provides the
options to the user to restrict (filter) the grid.

The user changes the drop downs and then uses the Filter button to
filter data (grid) that is the correct behavior.
Now imagine that the user plays with the dropdowns, but he doesn't
want to apply the filter and after he chooses to walk to a different
page, that action will cause a postback of data, and the dropdown
selections will be effective applied due to be changed by a previous
use in the interface.

The question is how can i avoid the postback (or ignore it) when
postback is not fired due to the action of the "Fire" button ?

I think the solution probably need to be client side, because it's not
a problem of the grid filtering data based in the options, but also a
visual consistency, when you do a postback and the page is rendered to
the client the drop downs should reflect the filter applied.

Any ideas, thoughts ....

Thanks all for reading.

Regards,
TP
 
I'm not completely clear on all the server controls you are using.
But it sounds like you want capture all the post back events and set a
property or some variable depending on where the event was fired from
and adjust your processing accordingly. So something like this may do
the trick...

ASPX:
<asp:GridView ID="GridView1" runat="server"
PageIndexChanging="GridViewPageChange">
</asp:GridView>
<asp:Button ID="FilterButton" runat="server" Text="Filter"
onclick="FilterButton_Click" />



CodeBehind:
private Boolean _dropdownchange;

public Boolean IgnoreDropdownChange
{
get
{
if(_dropdownchange != null)
{
_dropdownchange = false;
}

return _dropdownchange;
}
set { _dropdownchange = value; }
}



protected void Page_Load(object sender, EventArgs e)
{

if(IgnoreDropdownChange)
{
bleh
bleh
}
}



protected void GridViewPageChange(object sender, EventArgs e)
{
IgnoreDropdownChange = true;
}
protected void FilterButton_Click(object sender, EventArgs e)
{
IgnoreDropdownChange = false;
}
 
Hi Jacerhea,

Thanks for your time, but the problem is not so simple or at least
it's more an unusual request...

I'll take the GridView out of the picture to simplify to the root of
the problem:

Imagine, you have 3 dropdowns or could be a mix of dropdowns and
textboxs (with autopostback="false") those controls are used to
filter each time you press a Filter button.

What i want to do is each time the page is postback is to validated if
the postback was originated because of the "Filter"'s click event, if
not i would like to ignore the postback data (dropdowns/filter
controls) and keep it the previous data (viewstate) or if it's the
first postback (init values).

The objective is the dropdowns/filter controls only keep the
selections if the user presses the filter, if the postback is caused
by other reason (gridview page event, or another button or whatever
reason) those controls should keep the "old" values and not the values
selected before the postback.

Regards,
TP
 
Hi Jacerhea,

Thanks for your time, but the problem is not so simple or at least
it's more an unusual request...

I'll take the GridView out of the picture to simplify to the root of
the problem:

Imagine, you have 3 dropdowns or could be a mix of dropdowns and
textboxs (with autopostback="false")  those controls are used to
filter each time you press a Filter button.

What i want to do is each time the page is postback is to validated if
the postback was originated because of the "Filter"'s click event, if
not i would like to ignore the postback data (dropdowns/filter
controls) and  keep it the previous data (viewstate) or if it's the
first postback (init values).

The objective is the dropdowns/filter controls only keep the
selections if the user presses the filter, if the postback is caused
by other reason (gridview page event, or another button or whatever
reason) those controls should keep the "old" values and not the values
selected before the postback.

Keep each value of our dropdown/filter controls in a session
variable. Only update those session variables when your Filter button
is clicked.

When the postback occurs, set the values of each control to what is in
the session variable.
 
Keep each value of our dropdown/filter controls in a session
variable.  Only update those session variables when your Filter button
is clicked.

When the postback occurs, set the values of each control to what is in
the session variable.

Larry,

Thanks for your time,

Using Session to store the filter data, is out of my options (by
design), normally using session leads to bad habits :).


I think i have only 2 options:


1) At the client level (Javascript), some logic like:
store current selections in a global variable
before the submit check if the postback was caused by the filter
button
if not replace/assign the selections/filter objects values with the
values stored in the global variable


2) At server side


I'm looking for ideas in both sides


Regards,
TP
 
Back
Top