Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > 1.1 vs 2.0 Textbox Control Text on Postback

Reply
Thread Tools

1.1 vs 2.0 Textbox Control Text on Postback

 
 
John Walker
Guest
Posts: n/a
 
      12-28-2007
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

 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      12-28-2007
"John Walker" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

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


Yes:
http://connect.microsoft.com/VisualS...dbackID=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

 
Reply With Quote
 
 
 
 
John Walker
Guest
Posts: n/a
 
      12-28-2007
Awesome. Don't know why that works any different, but if it works then great.
Thanks!

"Mark Rae [MVP]" wrote:

> "John Walker" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> > Did something change in 2.0 so that readonly text does not postback?

>
> Yes:
> http://connect.microsoft.com/VisualS...dbackID=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
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
<VS03>How to make the textbox text remain after postback zhixuen ASP .Net 0 02-10-2009 09:03 AM
Accessing Textbox Text After Postback in Dynamic Control Elroyskimms ASP .Net Building Controls 3 02-22-2006 04:44 PM
ASP.NET textbox loses text value in composite control but Textbox subclass doesn't!? ErwinP ASP .Net Web Controls 1 08-19-2005 01:50 PM
Datagrid embedded textbox text fill on postback Peppie ASP .Net 0 06-01-2005 06:59 PM
Re: VERY STRANGE BUG? Adding a textbox control causes other textbox control to fail??? S. Justin Gengo ASP .Net 0 07-16-2003 06:51 PM



Advertisments