IDでコンポーネントを取得する方法を知っている人がいらっしゃいましたら、TextBox_1
、TextBox_2
、TextBox_3
などの要素を含むループがあります。IDまたはその一部でVB.Net WebFormsコンポーネントを見つける方法は?
データベースから返されたデータリストに基づいてループを作成しました。私はエラーがテキストボックスが即時ビューでNothing
を返す。..未定義のオブジェクトであることを私に示してTextBox.Text = "My data"
にトリガされ
Dim count as Integer = 1
Dim TextBox As TextBox = Nothing
For Each dados In MyListData
TextBox = CType(Me.FindControl("TextBox_" & count), TextBox)
TextBox.Text = "My data"
count = count + 1
Next
のようなものを試してみました。
私のシナリオは、マスターページを使用したフォームであり、これにはUpdatePanelsコンポーネントを持つContentPlaceholdersが含まれています。 My TextBoxはWeb Form "Content"の中にあります。これはMasterのContentPlaceHolderのメインコンテンツに対応しています。最初は、Me.FindControl(上記)の要素を見つけることができたと思います。 Me.Form、Me.PageとMe.Control何も...
マスターページのようなものです:
<!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 id="Head1" runat="server">
<!-- My header.. -->
</head>
<body onkeydown="return(event.keyCode!=13);">
<%--<% If (DesignMode) Then%>
<script src="Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
<% End If%>--%>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="900">
</asp:ScriptManager>
<div id="buttons">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:ContentPlaceHolder ID="Header" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="container">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ContentPlaceHolder ID="Content" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
フォームマークアップは、このような構造である:私は
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/MyProject_Master.Master"
CodeBehind="Page.aspx.vb" Inherits="MyProject.MyForm" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Header" runat="server">
<!-- Some static HTML -->
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
<!-- The structure is like: -->
<table cellpadding="1" cellspacing="1" class="divLargura">
<tr>
<td><asp:Label ID="Label_1" runat="server"></asp:Label></td>
<td>
<asp:TextBox ID="TextBox_1" runat="server" ReadOnly="true" Width="97%" Height="18px" ClientIDMode="Static">
</asp:TextBox>
</td>
</tr>
<tr>
<td><asp:Label ID="Label_2" runat="server"></asp:Label></td>
<td>
<asp:TextBox ID="TextBox_2" runat="server" ReadOnly="true" Width="97%" Height="18px" ClientIDMode="Static">
</asp:TextBox>
</td>
</tr>
<tr>
<td><asp:Label ID="Label_3" runat="server"></asp:Label></td>
<td>
<asp:TextBox ID="TextBox_3" runat="server" ReadOnly="true" Width="97%" Height="18px" ClientIDMode="Static">
</asp:TextBox>
</td>
</tr>
<tr>
<td><asp:Label ID="Label_4" runat="server"></asp:Label></td>
<td>
<asp:TextBox ID="TextBox_4" runat="server" ReadOnly="true" Width="97%" Height="18px" ClientIDMode="Static">
</asp:TextBox>
</td>
</tr>
</table>
</asp:Content>
何をしています違う? ReadOnlyとの関係はありますか?
フィードバックありがとうございます@ジョエル! PS:今の例では、データリストの名前を「MyListData」に変更しました。それはMasterPageを使ったWebフォームです。 MasterPageには
素晴らしい...今質問を編集してすべての情報を表示してください。ここには完全な絵が必要です。 –
ありがとう@Joel Coehoorn、今更新されました。問題をより正確に詳細に助けてくれることを願っています。 – RPichioli