我创建了一个UserControl(带有2个文本框和1个标签)我在ListView中有这个UserControl。我有一个提交按钮,曾经是触发器我想读取(2个文本框和1个标签)的值对于列表视图的每一行。我有下面的代码但是当我试图阅读TextBoxes中的内容时它没有显示任何值。在用户控件中获取服务器控件的正确方法是什么?
SpecificExperienceControl.ascx
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="SpecificExperienceControl.ascx.vb" Inherits="TardyAbsenteeReport.SpecificExperienceControl" %>
<asp:HiddenField ID="hdnID" runat="server" />
<div class="SpecExp">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" CssClass="SpecExp-txtEmpID" ></asp:TextBox>
</td>
<td>
<asp:Label ID="Label1" runat="server" Text="Label" CssClass="SpecExp-txtLbl"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" CssClass="SpecExp-txtAcode"></asp:TextBox>
</td>
</tr>
</div>
SpecificExperience.aspx(在LIstView上使用我的UserControl绑定到xml文件以创建25行空数据
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="SpecificExperience.aspx.vb" Inherits="TardyAbsenteeReport.SpecificExperience" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" border="1" runat="server" id="tblProducts">
<tr id="Tr1" runat="server">
<th id="Th1" runat="server">EmployeeID</th>
<th id="Th2" runat="server">Name</th>
<th id="Th3" runat="server">Absentee Code</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<hr:SpecExp ID="SpecExp1" runat="server"></hr:SpecExp>
</ItemTemplate>
</asp:ListView>
<div>
<asp:Button ID="Button1" runat="server" Text="Submit" />
</div>
</asp:Content>
SpecificExperience.aspx.vb(尝试从用户控件内的服务器控件读取数据的代码
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim lview As ListViewItem
For Each lview In ListView1.Items
Dim LblEmployeeName As Label = lview.FindControl("SpecExp1$Label1")
Dim TxtEmployeeID As TextBox = lview.FindControl("SpecExp1$TextBox1")
Dim TxtAbsenteeCode As TextBox = lview.FindControl("SpecExp1$TextBox2")
Dim StrEmployeeId As String = TxtEmployeeID.Text
Dim StrLblemployee As String = LblEmployeeName.Text
Dim StrAbsentee As String = TxtAbsenteeCode.Text
Next
End Sub
答案 0 :(得分:0)
您是否正在检查是否发生了回发?听起来好像你不是,列表视图对每个按钮点击都是新鲜的约束力。