开发者

Changing Control's property in Update Panel

I am migrating my project开发者_Python百科 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


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">

<html xmlns="http://www.w3.org/1999/xhtml">
<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.


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 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜