1.1 vs 2.0 Textbox Control Text on Postback

Discussion in 'ASP .Net' started by John Walker, Dec 28, 2007.

  1. John Walker

    John Walker Guest

    Hi,
    In asp.net 1.1 I use this bit of code to get the text from a textbox in a
    datagrid on postback:

    txtComments = CType(dgi.FindControl("txtComments"),
    System.Web.UI.WebControls.TextBox)

    We recently upgraded our application to the 2.0 .net framework and this code
    no longer seems to work. It is a read-only textbox... the text is
    added/changed with javascipt. When we set readonly property on the textbox
    to False we are then able to successfully view the added/changed text on
    postback. Did something change in 2.0 so that readonly text does not
    postback? is there a way to get around it?

    Thanks,
    John
     
    John Walker, Dec 28, 2007
    #1
    1. Advertising

  2. "John Walker" <> wrote in message
    news:...

    > Did something change in 2.0 so that readonly text does not postback?


    Yes:
    http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102065

    > is there a way to get around it?


    Yes.


    Instead of this:

    <asp:TextBox ID="MyTextBox" runat="server" ReadOnly="True" />


    do this:

    <asp:TextBox ID="MyTextBox" runat="server" />


    and in your code behind do this:

    protected void Page_Load(object sender, EventArgs e)
    {
    MyTextBox.Attributes.Add("readonly", "readonly");
    }


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Dec 28, 2007
    #2
    1. Advertising

  3. John Walker

    John Walker Guest

    Awesome. Don't know why that works any different, but if it works then great.
    Thanks!

    "Mark Rae [MVP]" wrote:

    > "John Walker" <> wrote in message
    > news:...
    >
    > > Did something change in 2.0 so that readonly text does not postback?

    >
    > Yes:
    > http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102065
    >
    > > is there a way to get around it?

    >
    > Yes.
    >
    >
    > Instead of this:
    >
    > <asp:TextBox ID="MyTextBox" runat="server" ReadOnly="True" />
    >
    >
    > do this:
    >
    > <asp:TextBox ID="MyTextBox" runat="server" />
    >
    >
    > and in your code behind do this:
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > MyTextBox.Attributes.Add("readonly", "readonly");
    > }
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
     
    John Walker, Dec 28, 2007
    #3
    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. S. Justin Gengo
    Replies:
    0
    Views:
    576
    S. Justin Gengo
    Jul 16, 2003
  2. Peppie
    Replies:
    0
    Views:
    843
    Peppie
    Jun 1, 2005
  3. zhixuen
    Replies:
    0
    Views:
    1,248
    zhixuen
    Feb 10, 2009
  4. Elroyskimms

    Accessing Textbox Text After Postback in Dynamic Control

    Elroyskimms, Feb 20, 2006, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    503
    Jose Rodriguez
    Feb 22, 2006
  5. ErwinP
    Replies:
    1
    Views:
    815
    ErwinP
    Aug 19, 2005
Loading...

Share This Page