tags:

views:

237

answers:

2

Hi,

I am migrating my project from 2003 to asp.net 2008.My problem is about Readonly Textboxes.I have some textboxes as readonly.In 2008,i cant get values from these textboxes if readonly=true in aspx.So i write a function which converts readonly=false and add readonly attribute in run-time.It works well if my textbox is not in update panel.In Update panel,page's controls doesnt come to my class cause just one control comes.It is UpdatePanel.How can i get controls in Update Panel and how can i change it?My code is following.I call it in everypage.

Public Shared Sub clearReadOnlyTextboxes(ByVal pg As Page)
    For Each c As Control In pg.Form.Controls
        If c.[GetType]().ToString() = "System.Web.UI.WebControls.TextBox" AndAlso DirectCast(c, TextBox).[ReadOnly] Then
            DirectCast(c, TextBox).[ReadOnly] = False
            DirectCast(c, TextBox).Attributes.Add("readonly", "readonly")
        End If
    Next
End Sub
A: 

I created a new ASP.NET website in Visual Studio 2008 SP1 with .NET 3.5 as the target framework. I was able to use the value from a readonly textbox to update the value of a label.

Here is the example:

Designer:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
</head>

<body>
    <form id="form1" runat="server">

    <div>
    <asp:textbox ID="Textbox1" runat="server" ReadOnly="True"></asp:textbox>
    </div>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>
</body>
</html>

Code behind:

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
       Textbox1.Text = "GANESH";
       Label1.Text = Textbox1.Text;
    }
}

Any inputs from you will help us help you.

Ganesh R.
thanks but postback causes this issue.Look at this link,u will understand what i mean.http://aspadvice.com/blogs/joteke/archive/2006/04/12/16409.aspx
Alexander
ohh...But one question, if the user cannot change the data, why not use the data from the data source which was used to fill in the data in the textbox in the first place.
Ganesh R.
i am using these textboxes for javascript datecalendar.They hold date information and i am listing records depend on these textboxes.
Alexander
A: 

Hi,

Try Using this.. It will get all the controls in Panel...

 Private Sub clearReadOnlyTextboxes(ByVal pg As Control)
            For Each c As Control In pg.Controls
                Select Case TypeName(c)
                    Case Is = "TextBox"
                        If c.[GetType]().ToString() = "System.Web.UI.WebControls.TextBox" AndAlso DirectCast(c, TextBox).[ReadOnly] Then
                            DirectCast(c, TextBox).[ReadOnly] = False
                            DirectCast(c, TextBox).Attributes.Add("readonly", "readonly")
                        End If
                    Case Is = "Panel"
                        clearReadOnlyTextboxes(c)
                    Case Is = "HtmlForm"
                        clearReadOnlyTextboxes(c)
                End Select
            Next
        End Sub 
Karthik.P.S