Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 改变控制';更新面板中的属性_.net_Asp.net - Fatal编程技术网

.net 改变控制';更新面板中的属性

.net 改变控制';更新面板中的属性,.net,asp.net,.net,Asp.net,我正在将我的项目从2003迁移到asp.net 2008。我的问题是关于只读文本框。我有一些文本框为只读。在2008年,如果在aspx中readonly=true,我无法从这些文本框中获取值。因此,我编写了一个函数,该函数将readonly=false转换,并在运行时添加readonly属性。如果我的文本框不在更新面板中,则效果良好。在更新面板中,页面的控件没有出现在我的类中,因为只有一个控件出现。它是UpdatePanel。我如何在更新面板中获取控件以及如何更改它?我的代码如下。我在每个页面中

我正在将我的项目从2003迁移到asp.net 2008。我的问题是关于只读文本框。我有一些文本框为只读。在2008年,如果在aspx中readonly=true,我无法从这些文本框中获取值。因此,我编写了一个函数,该函数将readonly=false转换,并在运行时添加readonly属性。如果我的文本框不在更新面板中,则效果良好。在更新面板中,页面的控件没有出现在我的类中,因为只有一个控件出现。它是UpdatePanel。我如何在更新面板中获取控件以及如何更改它?我的代码如下。我在每个页面中调用它

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

我在VisualStudio2008SP1中创建了一个新的ASP.NET网站,目标框架是.NET3.5。我可以使用只读文本框中的值来更新标签的值

以下是一个例子:

设计师:

<%@ 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> 

您的任何输入都将有助于我们帮助您。

尝试使用此功能。。它将获得面板中的所有控件

 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 

你是说.NET1.1到.NET3.5?或者Visula Studio 2003到Visual Studio 2008?Visula Studio 2003到Visual Studio 2008。迁移后我当然使用.Net 3,5。谢谢,但回发会导致此问题。查看此链接,您将理解我的意思。哦…但有一个问题,如果用户无法更改数据,为什么不首先使用用于在文本框中填充数据的数据源中的数据。我将这些文本框用于javascript datecalendar。它们保存日期信息,我将根据这些文本框列出记录。
 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