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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tiago.private@gmail.com

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

    Hi everybody,

    Imagine the following scenario:
    One System.Web.UI.U serControl (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
  • jacerhea

    #2
    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"
    PageIndexChangi ng="GridViewPag eChange">
    </asp:GridView>
    <asp:Button ID="FilterButto n" runat="server" Text="Filter"
    onclick="Filter Button_Click" />



    CodeBehind:
    private Boolean _dropdownchange ;

    public Boolean IgnoreDropdownC hange
    {
    get
    {
    if(_dropdowncha nge != null)
    {
    _dropdownchange = false;
    }

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



    protected void Page_Load(objec t sender, EventArgs e)
    {

    if(IgnoreDropdo wnChange)
    {
    bleh
    bleh
    }
    }



    protected void GridViewPageCha nge(object sender, EventArgs e)
    {
    IgnoreDropdownC hange = true;
    }
    protected void FilterButton_Cl ick(object sender, EventArgs e)
    {
    IgnoreDropdownC hange = false;
    }

    Comment

    • tiago.private@gmail.com

      #3
      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="f alse") 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

      Comment

      • Larry Bud

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

        On Nov 16, 2:40 pm, tiago.priv...@g mail.com 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="f alse")  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.

        Comment

        • tiago.private@gmail.com

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

          On Nov 16, 2:52 pm, Larry Bud <larrybud2...@y ahoo.comwrote:
          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



          Comment

          Working...