확인
===================================, 귀하의 편집 된 질문, 나는 당신을 위해 일해야 UserControl을 만들었습니다.
ASCX :
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="MultiFieldTextbox.ascx.vb" Inherits="WebApplication2.MultiFieldTextbox" %>
<asp:Panel ID="PnlBasic" Visible="false" runat="server">
<asp:TextBox ID="TxtFields" runat="server" TextMode="MultiLine" Width="200" Height="200"></asp:TextBox>
</asp:Panel>
<asp:Panel ID="PnlExtended" Visible="true" runat="server">
<asp:TextBox ID="TxtAddress1" runat="server"></asp:TextBox>
<asp:TextBox ID="TxtAddress2" runat="server"></asp:TextBox>
<asp:TextBox ID="TxtAddress3" runat="server"></asp:TextBox>
<asp:TextBox ID="TxtCity" runat="server"></asp:TextBox>
<asp:TextBox ID="TxtState" runat="server"></asp:TextBox>
<asp:TextBox ID="TxtZip" runat="server"></asp:TextBox>
<asp:TextBox ID="TxtCountry" runat="server"></asp:TextBox>
</asp:Panel>
<asp:Button ID="BtnSwitchMode" runat="server" Text="switch mode" />
ASCX-코드 숨김 : 물론 당신은 당신의 필요 조건에 레이아웃을 변경해야
작동
Public Class MultiFieldTextbox
Inherits System.Web.UI.UserControl
Public Enum ViewMode As Int32
Basic
Extended
End Enum
Public Property Mode As ViewMode
Get
If Me.PnlBasic.Visible Then
Return MultiFieldTextbox.ViewMode.Basic
Else
Return MultiFieldTextbox.ViewMode.Extended
End If
End Get
Set(ByVal value As ViewMode)
Me.PnlBasic.Visible = value = ViewMode.Basic
Me.PnlExtended.Visible = value = ViewMode.Extended
InitNewMode(value)
End Set
End Property
Public Property Addr1 As String
Get
Return Me.TxtAddress1.Text.Trim
End Get
Set(ByVal value As String)
Me.TxtAddress1.Text = value.Trim
End Set
End Property
Public Property Addr2 As String
Get
Return Me.TxtAddress2.Text.Trim
End Get
Set(ByVal value As String)
Me.TxtAddress2.Text = value.Trim
End Set
End Property
Public Property Addr3 As String
Get
Return Me.TxtAddress3.Text.Trim
End Get
Set(ByVal value As String)
Me.TxtAddress3.Text = value.Trim
End Set
End Property
Public Property City As String
Get
Return Me.TxtCity.Text.Trim
End Get
Set(ByVal value As String)
Me.TxtCity.Text = value.Trim
End Set
End Property
Public Property State As String
Get
Return Me.TxtState.Text.Trim
End Get
Set(ByVal value As String)
Me.TxtState.Text = value.Trim
End Set
End Property
Public Property Zip As String
Get
Return Me.TxtZip.Text.Trim
End Get
Set(ByVal value As String)
Me.TxtZip.Text = value.Trim
End Set
End Property
Public Property Country As String
Get
Return Me.TxtCountry.Text.Trim
End Get
Set(ByVal value As String)
Me.TxtCountry.Text = value.Trim
End Set
End Property
Private Property FieldInfos As Dictionary(Of String, FieldInfo)
Get
If ViewState("FieldInfos") Is Nothing Then
ViewState("FieldInfos") = New Dictionary(Of String, FieldInfo)
End If
Return DirectCast(ViewState("FieldInfos"), Dictionary(Of String, FieldInfo))
End Get
Set(ByVal value As Dictionary(Of String, FieldInfo))
ViewState("FieldInfos") = value
End Set
End Property
Private Sub InitNewMode(ByVal newMode As ViewMode)
Select Case newMode
Case ViewMode.Basic
Dim builder As New Text.StringBuilder
Dim lineNumber As Int32 = 0
Dim key = "Addr1"
Dim field = Me.Addr1
FieldInfos = New Dictionary(Of String, FieldInfo)
lineNumber += 1
If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine))
FieldInfos.Add(key, New FieldInfo(lineNumber, key, field))
key = "Addr2"
field = Me.Addr2
lineNumber += 1
If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine))
FieldInfos.Add(key, New FieldInfo(lineNumber, key, field))
key = "Addr3"
field = Me.Addr3
lineNumber += 1
If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine))
FieldInfos.Add(key, New FieldInfo(lineNumber, key, field))
key = "City"
field = Me.City
lineNumber += 1
If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine))
FieldInfos.Add(key, New FieldInfo(lineNumber, key, field))
key = "State"
field = Me.State
lineNumber += 1
If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine))
FieldInfos.Add(key, New FieldInfo(lineNumber, key, field))
key = "Zip"
field = Me.Zip
lineNumber += 1
If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine))
FieldInfos.Add(key, New FieldInfo(lineNumber, key, field))
key = "Country"
field = Me.Country
lineNumber += 1
If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine))
FieldInfos.Add(key, New FieldInfo(lineNumber, key, field))
If builder.Length <> 0 Then builder.Length -= ControlChars.NewLine.Length
Me.TxtFields.Text = builder.ToString
Case ViewMode.Extended
Dim lineNumber As Int32 = 0
Dim allLines = Me.TxtFields.Text.Split(New String() {ControlChars.NewLine}, StringSplitOptions.None)
For Each line In allLines
lineNumber += 1
' set value via old line number '
Dim q = From field In Me.FieldInfos
Where field.Value.Line = lineNumber
Select field
If q.Any Then
Me.FieldInfos(q.First.Key).Value = line
End If
Next
Dim diff = FieldInfos.Count - allLines.Length
If diff <> 0 Then
Dim line As Int32
For line = (1 + allLines.Length) To (diff + allLines.Length)
' set value=String.Empty for each missing line '
Dim q = From field In Me.FieldInfos
Where field.Value.Line = line
Select field
If q.Any Then
Me.FieldInfos(q.First.Key).Value = String.Empty
End If
Next
End If
Me.Addr1 = Me.FieldInfos("Addr1").Value
Me.Addr2 = Me.FieldInfos("Addr2").Value
Me.Addr3 = Me.FieldInfos("Addr3").Value
Me.City = Me.FieldInfos("City").Value
Me.State = Me.FieldInfos("State").Value
Me.Zip = Me.FieldInfos("Zip").Value
Me.Country = Me.FieldInfos("Country").Value
End Select
End Sub
Protected Sub BtnSwitchMode_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnSwitchMode.Click
Dim newMode As ViewMode = If(Me.Mode = ViewMode.Basic, ViewMode.Extended, ViewMode.Basic)
Me.Mode = newMode
End Sub
End Class
<Serializable()>
Public Class FieldInfo
Public Property ID As String
Public Property Value As String
Public Property Line As Int32
Public Sub New(ByVal line As Int32, ByVal ID As String, ByVal Value As String)
Me.Line = line
Me.ID = ID
Me.Value = Value
End Sub
End Class
경우 모든 주소 라인 (ADD1, ADD2 , add3, city, state, zip, country)가 입력됩니다. add1, add3, state, country를 지정한 다음 확장 모드의 해당 텍스트 상자에 정확하게 배치하는 방법을 알려줍니다. –
감사합니다 Tim.it은 모든 add1, add2, add3, city, state, zip, country가 주어지면 작동합니다. 어떻게하면 add1, add3, state, country 만 부여 할 수 있습니까? 어떻게하면 add2가 비어 있고 add3가 올바른 텍스트 상자에 배치되었는지 알 수 있습니다. 그래서 도움이됩니다. –
@Kompella : 문제를 이해하지 못합니다. 필드가 7 개 있습니다. 기본 모드로 전환하면 길이가 7 인 문자열 배열이 위 속성에 전달됩니다. Textbox.Text는 각 필드 다음에 NewLines으로 올바르게 채워집니다. 사용자가 한 줄을 제거하면 String Array (빈 줄)에 여전히있는 빈 줄이 생기고 Array-Length는 여전히 7입니다. 따라서 확장 모드로 전환하는 데 문제가 없어야합니다. –