My button_click function doesn't get current value

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

    My button_click function doesn't get current value

    I have an image button that I do an button_click with

    protected void ImageButton1_Cl ick(object sender, ImageClickEvent Args e)
    {
    stringt value1=TextBox1 .Text;

    I get the value here ok, but only if I don't set it in the pageload part.
    TextBox7.Text=" a"; // if this is in the pageload, I will always get "a"

    I want to be able to change the value on the page, and have it show up in
    ImageButton1_Cl ick. Anyone know why this is happening.



  • Scott Roberts

    #2
    Re: My button_click function doesn't get current value

    By the time the Page_Load event occurs, TextBox7 has already been loaded
    with the value entered on the page. So when you set TextBox7.Text = "a" you
    are overwriting the value entered by the user.

    The general practice for initializing control values in Page_Load is as
    follows:

    if (!IsPostBack)
    {
    TextBox7.Text = "a";
    }

    That way the control value is only initialized on the initial page load, but
    not on any postbacks.

    Scott


    "Cindy Lee" <cindylee@hotma il.comwrote in message
    news:uSqIqd6KIH A.3848@TK2MSFTN GP05.phx.gbl...
    >I have an image button that I do an button_click with
    >
    protected void ImageButton1_Cl ick(object sender, ImageClickEvent Args e)
    {
    stringt value1=TextBox1 .Text;
    >
    I get the value here ok, but only if I don't set it in the pageload part.
    TextBox7.Text=" a"; // if this is in the pageload, I will always get "a"
    >
    I want to be able to change the value on the page, and have it show up in
    ImageButton1_Cl ick. Anyone know why this is happening.
    >
    >
    >

    Comment

    • Cindy Lee

      #3
      Re: My button_click function doesn't get current value

      Ahh, thanks. cleared things up.

      "Scott Roberts" <sroberts@no.sp am.here-webworks-software.comwro te in
      message news:ufRY7l6KIH A.5860@TK2MSFTN GP04.phx.gbl...
      By the time the Page_Load event occurs, TextBox7 has already been loaded
      with the value entered on the page. So when you set TextBox7.Text = "a"
      you
      are overwriting the value entered by the user.
      >
      The general practice for initializing control values in Page_Load is as
      follows:
      >
      if (!IsPostBack)
      {
      TextBox7.Text = "a";
      }
      >
      That way the control value is only initialized on the initial page load,
      but
      not on any postbacks.
      >
      Scott
      >
      >
      "Cindy Lee" <cindylee@hotma il.comwrote in message
      news:uSqIqd6KIH A.3848@TK2MSFTN GP05.phx.gbl...
      I have an image button that I do an button_click with

      protected void ImageButton1_Cl ick(object sender, ImageClickEvent Args e)
      {
      stringt value1=TextBox1 .Text;

      I get the value here ok, but only if I don't set it in the pageload
      part.
      TextBox7.Text=" a"; // if this is in the pageload, I will always get
      "a"

      I want to be able to change the value on the page, and have it show up
      in
      ImageButton1_Cl ick. Anyone know why this is happening.

      >

      Comment

      Working...