asp-net-findcontrol-template ソースコード全文

AspNetFindControl_CS.sln

AspNetFindControl_CS.sln
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35004.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "AspNetFindControl_CS", "AspNetFindControl_CS\", "{E4C136CD-ABB5-46F9-9393-2DCD30CCEECB}"
ProjectSection(WebsiteProperties) = preProject
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.8"
Debug.AspNetCompiler.VirtualPath = "/localhost_51120"
Debug.AspNetCompiler.PhysicalPath = "AspNetFindControl_CS\"
Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_51120\"
Debug.AspNetCompiler.Updateable = "true"
Debug.AspNetCompiler.ForceOverwrite = "true"
Debug.AspNetCompiler.FixedNames = "false"
Debug.AspNetCompiler.Debug = "True"
Release.AspNetCompiler.VirtualPath = "/localhost_51120"
Release.AspNetCompiler.PhysicalPath = "AspNetFindControl_CS\"
Release.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_51120\"
Release.AspNetCompiler.Updateable = "true"
Release.AspNetCompiler.ForceOverwrite = "true"
Release.AspNetCompiler.FixedNames = "false"
Release.AspNetCompiler.Debug = "False"
VWDPort = "51120"
SlnRelativePath = "AspNetFindControl_CS\"
DefaultWebSiteLanguage = "Visual C#"
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E4C136CD-ABB5-46F9-9393-2DCD30CCEECB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4C136CD-ABB5-46F9-9393-2DCD30CCEECB}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {57FEB6AE-B84E-49A5-9C26-841B8187280D}
EndGlobalSection
EndGlobal

AspNetFindControl_CS/Default.aspx

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button runat="server" ID="Button1" Text="Button" OnClick="Button1_Click"></asp:Button>
<div style="display:flex;flex-direction: column; width:75%;">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text="<%# Container.DataItem %>"></asp:TextBox>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
</form>
</body>
</html>

AspNetFindControl_CS/Default.aspx.cs

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<string> values = new List<string>();
values.Add("アイ");
values.Add("マイ");
values.Add("ミー");
values.Add("マイン");
this.Repeater1.DataSource = values;
this.Repeater1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in this.Repeater1.Items)
{
TextBox tbox = item.FindControl("TextBox1") as TextBox;
if(tbox == null)
{
return;
}
Debug.WriteLine(item.ItemIndex + 1 + " つ目の値: " + tbox.Text);
if (item.ItemIndex == 1)
{
tbox.Focus();
}
}
}
}

AspNetFindControl_CS/packages.config

packages.config
<?xml version="1.0" encoding="utf-8"?>
<!--<packages>
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net48" />
</packages>-->

AspNetFindControl_CS/Web.config

Web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
ASP.NET アプリケーションの構成方法の詳細については、
https://go.microsoft.com/fwlink/?LinkId=169433 を参照してください
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.8" />
<httpRuntime targetFramework="4.8" />
</system.web>
<!--<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>-->
</configuration>

AspNetFindControl_CS/Web.Debug.config

Web.Debug.config
<?xml version="1.0" encoding="utf-8"?>
<!-- web.config 変換の使用方法の詳細については、https://go.microsoft.com/fwlink/?LinkId=125889 を参照してください -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
次の例では、"MyDB" という値を持つ "name" 属性が "Match" ロケーターで
見つかった場合にのみ、"SetAttributes" 変換によって "connectionString" の
値が "ReleaseSQLServer" を使用するように変更されます。
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
次の例では、web.config ファイルの <customErrors> セクション全体が
"Replace" 変換によって置き換えられます。
<system.web> ノードには customErrors セクションが 1 つしかないため、
"xdt:Locator" 属性を使用する必要はありません。
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
>
-->
</system.web>
</configuration>