Postback nightmares

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doogie

    Postback nightmares

    Basically, I have two custom dates the user can enter via a popup
    calendar. These dates are stored into text boxes. Then the user can
    click a button (Run Report) and those values (as well as others) are
    used to build an SRS url string. This used to work before I modified
    the page to make the calendar a popup.

    Now, the text boxes lose their value when the user clicks the run
    report button. I have verified this is happening because it’s doing a
    postback, but the values are gone before page_load is called. I have
    EnableViewState set to true for both text boxes and it’s not retaining
    the values. I have tried variations of ways to fix this (set the
    values in a view state object, enable view state on the page as a
    whole, etc) and nothing is working.

    Am I missing something?
  • Peter Bromberg [C# MVP]

    #2
    Re: Postback nightmares

    It sound like you are capturing the entered values from the popup
    client-side, and therefore there is no server-side TextChanged event or
    ViewState populated.
    Of course, when the postback is created, you get two empty textboxes because
    valuess populated in the browser don't get transmitted. Among other tricks,
    you could try storing them in a cookie first - that can be done client-side
    via javascript. Then read back the cookie on a postback and you can get your
    values.
    Peter

    "Doogie" <dnlwhite@dtgne t.comwrote in message
    news:036bd68e-8158-45ee-81fc-af79c6a3b696@27 g2000hsf.google groups.com...
    Basically, I have two custom dates the user can enter via a popup
    calendar. These dates are stored into text boxes. Then the user can
    click a button (Run Report) and those values (as well as others) are
    used to build an SRS url string. This used to work before I modified
    the page to make the calendar a popup.

    Now, the text boxes lose their value when the user clicks the run
    report button. I have verified this is happening because it’s doing a
    postback, but the values are gone before page_load is called. I have
    EnableViewState set to true for both text boxes and it’s not retaining
    the values. I have tried variations of ways to fix this (set the
    values in a view state object, enable view state on the page as a
    whole, etc) and nothing is working.

    Am I missing something?

    Comment

    • Doogie

      #3
      Re: Postback nightmares

      On May 1, 10:38 am, "Peter Bromberg [C# MVP]"
      <pbromb...@nosp ammin.yahoo.com wrote:
      It sound like you are capturing the entered values from the popup
      client-side, and therefore there is no server-side TextChanged event or
      ViewState populated.
      Of course, when the postback is created, you get two empty textboxes because
      valuess populated in the browser don't get transmitted. Among other tricks,
      you could try storing them in a cookie first - that can be done client-side
      via javascript. Then read back the cookie on a postback and you can get your
      values.
      Peter
      >
      "Doogie" <dnlwh...@dtgne t.comwrote in message
      >
      news:036bd68e-8158-45ee-81fc-af79c6a3b696@27 g2000hsf.google groups.com...
      Basically, I have two custom dates the user can enter via a popup
      calendar.  These dates are stored into text boxes.  Then the user can
      click a button (Run Report) and those values (as well as others) are
      used to build an SRS url string.  This used to work before I modified
      the page to make the calendar a popup.
      >
      Now, the text boxes lose their value when the user clicks the run
      report button.  I have verified this is happening because it’s doing a
      postback, but the values are gone before page_load is called.  I have
      EnableViewState set to true for both text boxes and it’s not retaining
      the values.  I have tried variations of ways to fix this (set the
      values in a view state object, enable view state on the page as a
      whole, etc) and nothing is working.
      >
      Am I missing something?
      Turns out that the fact the text boxes are disabled is what is causing
      the issue. Setting them to be enabled fixed the issue. Weird, not
      sure why I wouldn't be able to do that. I have them disabled cause I
      wanted them to only be filled by the calendar popup and not manually
      entered.

      Comment

      • Mark Rae [MVP]

        #4
        Re: Postback nightmares

        "Doogie" <dnlwhite@dtgne t.comwrote in message
        news:c59f6994-27bd-48db-a177-4b7e4a8348b8@34 g2000hsf.google groups.com...
        Turns out that the fact the text boxes are disabled is what is causing
        the issue. Setting them to be enabled fixed the issue. Weird, not
        sure why I wouldn't be able to do that. I have them disabled cause I
        wanted them to only be filled by the calendar popup and not manually
        entered.
        Aha! I've seen that before.

        Had you disabled the textboxes in the actual markup i.e. in the <asp:TextBox
        tag?
        If so, try disabling them in codebehind e.g.

        TextBox1.Enable d = false;

        or even

        TextBox1.Attrib utes.Add("disab led", "disabled") ;


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • Teemu Keiski

          #5
          Re: Postback nightmares

          Hi,

          You could set submitdisabledc ontrols="true" on the <formelement of the
          page which makes asp.net to post also disabled textboxes values. I believe
          disabled HTML form elements don't submit by default.

          Other option is to set TextBox as readonly but that has to be done via
          Attributes.Add
          (http://aspadvice.com/blogs/joteke/ar.../12/16409.aspx) as setting
          ReadOnly property prevents postback data from being loaded, meaning in
          practise that TextBox doesn't keep its state (it's read-only from
          server-side perspective)


          --
          Teemu Keiski
          AspInsider, ASP.NET MVP




          "Doogie" <dnlwhite@dtgne t.comwrote in message
          news:c59f6994-27bd-48db-a177-4b7e4a8348b8@34 g2000hsf.google groups.com...
          On May 1, 10:38 am, "Peter Bromberg [C# MVP]"
          <pbromb...@nosp ammin.yahoo.com wrote:
          It sound like you are capturing the entered values from the popup
          client-side, and therefore there is no server-side TextChanged event or
          ViewState populated.
          Of course, when the postback is created, you get two empty textboxes
          because
          valuess populated in the browser don't get transmitted. Among other
          tricks,
          you could try storing them in a cookie first - that can be done
          client-side
          via javascript. Then read back the cookie on a postback and you can get
          your
          values.
          Peter
          >
          "Doogie" <dnlwh...@dtgne t.comwrote in message
          >
          news:036bd68e-8158-45ee-81fc-af79c6a3b696@27 g2000hsf.google groups.com...
          Basically, I have two custom dates the user can enter via a popup
          calendar. These dates are stored into text boxes. Then the user can
          click a button (Run Report) and those values (as well as others) are
          used to build an SRS url string. This used to work before I modified
          the page to make the calendar a popup.
          >
          Now, the text boxes lose their value when the user clicks the run
          report button. I have verified this is happening because it’s doing a
          postback, but the values are gone before page_load is called. I have
          EnableViewState set to true for both text boxes and it’s not retaining
          the values. I have tried variations of ways to fix this (set the
          values in a view state object, enable view state on the page as a
          whole, etc) and nothing is working.
          >
          Am I missing something?
          Turns out that the fact the text boxes are disabled is what is causing
          the issue. Setting them to be enabled fixed the issue. Weird, not
          sure why I wouldn't be able to do that. I have them disabled cause I
          wanted them to only be filled by the calendar popup and not manually
          entered.


          Comment

          Working...