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

Discussion in 'ASP .Net' started by tiago.private@gmail.com, Nov 15, 2008.

  1. Guest

    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
     
    , Nov 15, 2008
    #1
    1. Advertising

  2. jacerhea Guest

    Re: how can i avoid the postback (or ignore it) when not originatedby a specific button

    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;
    }
     
    jacerhea, Nov 16, 2008
    #2
    1. Advertising

  3. Guest

    Re: how can i avoid the postback (or ignore it) when not originatedby a specific button

    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
     
    , Nov 16, 2008
    #3
  4. Larry Bud Guest

    Re: how can i avoid the postback (or ignore it) when not originatedby a specific button

    On Nov 16, 2:40 pm, wrote:
    > 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.
     
    Larry Bud, Nov 16, 2008
    #4
  5. Guest

    Re: how can i avoid the postback (or ignore it) when not originatedby a specific button

    On Nov 16, 2:52 pm, Larry Bud <> wrote:

    > 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
     
    , Nov 17, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexander Malkis
    Replies:
    8
    Views:
    538
    Alexander Malkis
    Apr 14, 2004
  2. Robert Allan Schwartz

    Who originated the term "Miranda function"?

    Robert Allan Schwartz, Jul 4, 2004, in forum: C++
    Replies:
    15
    Views:
    889
    Old Wolf
    Jul 6, 2004
  3. PeteOlcott
    Replies:
    1
    Views:
    964
    Mukul Gandhi
    Feb 5, 2009
  4. Rob Meade
    Replies:
    6
    Views:
    293
    Rob Meade
    Mar 1, 2004
  5. Jesper Rønn-Jensen
    Replies:
    4
    Views:
    146
    Joel VanderWerf
    Feb 22, 2008
Loading...

Share This Page