0

プロジェクトのあるバージョンから新しいバージョンにユーザー コントロールを移行中です。バージョンを変更しようとしたところ、プロジェクトでエラーが発生したため、新しいプロジェクトを作成し、ページとコントロールのコピーを開始しました。ようやくすべてのコントロールをコピーして、ページをコピーしています。私は行くにつれてすべてをテストしています。

そうは言っても、私はコントロールに取り組んでおり、必要なフィールドバリデーターに問題があることに気付きました。これらのフィールドは動的ではないため、常に存在します。必要なバリデーターからのテストに失敗したフィールドには、データが含まれていました。問題が発生したのは 3 つでした。3 つすべてがテキスト フィールドです。2 つのバリデーターをカスタム バリデーターに変換して動作させることができましたが、3 つ目はまだ動作しません。

ページからの値がコントロールに再ロードされないため、動作していないカスタム バリデータは失敗します。コントロールの一意の ID を使用してフォームに投稿されたものを確認すると、データが存在します。この切断の原因は何ですか? コントロールのイベントが発生する前に、コントロールがポスト データでリロードされることになっていることを理解しています。このプロセスが壊れているようです。何が起こっている可能性がありますか?

問題のフィールドは、txtTitle、txtDescription、および txtSendNoticeTo です。

HTML:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ProjectInformation.ascx.vb" Inherits="KDoc.ProjectInformation" %>
<%@ Register TagPrefix="cc1" Namespace="SqlInjectionControls" Assembly="SqlInjectionControls" %>

<script type="text/javascript">
<!--
function addSendToName() {

    var textField = document.getElementById('ctl08_txtSendNoticeTo');
    //      alert(document.getElementById(textFieldId));

    if (textField.value.length > 0) {
        textField.value += "; " + document.getElementById('ctl08_ddlSendToNames').value;
    } else {
        textField.value = document.getElementById('ctl08_ddlSendToNames').value;
    }
}
//-->
</script>

<table class="fullWidth padding-2 spacing-3" border="0">
<tr>
    <td class="nowrap" style="width: 15%">Platform&nbsp;<span class="Required">*</span></td>
    <td style="width: 35%">
        <asp:dropdownlist id="ddlPlatform" Runat="server"/><br/>
        <asp:requiredfieldvalidator id="reqPlatform" Runat="server" ControlToValidate="ddlPlatform" Display="Dynamic" ErrorMessage="Required"/>
    </td>
    <td colSpan="2" class="right">
        <asp:LinkButton ID=btnChangeNotice CausesValidation=false runat=server Text="Change Notice Report" Visible=false />
    </td>
</tr>
<tr>
    <td class="nowrap" style="width: 15%">Area Manager&nbsp;<span class="Required">*</span></td>
    <td style="width: 35%">
        <asp:dropdownlist id="ddlSystem" Width="100%" Runat="server"/><br/>
        <asp:requiredfieldvalidator id="reqSystem" Runat="server" ControlToValidate="ddlSystem" Display="Dynamic" ErrorMessage="Required"/>
    </td>
    <td class="nowrap" style="width: 15%">Application</td>
    <td style="width: 35%">
        <asp:textbox id="txtApplication" Width="100%" MaxLength="100" Runat="server"/>
        <cc1:sqlinjectionvalidator id="sqlApplication" runat="server" ControlToValidate="txtApplication" ErrorMessage="Error in input field"/>
    </td>
</tr>
<tr>
    <td class="nowrap" style="width: 15%">Menu</td>
    <td style="width: 35%">
        <asp:textbox id="txtMenu" Width="100%" MaxLength="100" Runat="server"/>
        <cc1:sqlinjectionvalidator id="sqlMenu" runat="server" ControlToValidate="txtMenu" ErrorMessage="Error in input field"/>
    <td class="nowrap" style="width: 15%">Step</td>
    <td style="width: 35%">
        <asp:textbox id="txtMenuStep" Width="100%" MaxLength="100" Runat="server"/>
        <cc1:sqlinjectionvalidator id="sqlMenuStep" runat="server" ControlToValidate="txtMenuStep" ErrorMessage="Error in input field"/>
    </td>
<tr>
    <td class="nowrap" style="width: 15%">Title&nbsp;<span class="Required">*</span></td>
    <td colSpan="3">
        <asp:textbox id="txtTitle" Width="100%" MaxLength="100" Runat="server"/>
        <asp:CustomValidator ID="cvTitle" runat="server" ControlToValidate="txtTitle" Display="Dynamic" ErrorMessage="Required" />
        <cc1:sqlinjectionvalidator id="sqlTitle" runat="server" ControlToValidate="txtTitle" ErrorMessage="Error in input field"/>
    </td>
</tr>
<tr class="top">
    <td class="nowrap" style="width: 15%">Description&nbsp;<span class="Required">*</span></td>
    <td colSpan="3">
        <asp:textbox id="txtDescription" Width="100%" Runat="server" Height="150" TextMode="MultiLine"/>
        <asp:CustomValidator ID="cvDescription" runat="server" ControlToValidate="txtDescription" Display="Dynamic" ErrorMessage="Required" />
        <cc1:sqlinjectionvalidator id="sqlDescription" runat="server" ControlToValidate="txtDescription" ErrorMessage="Error in input field"/>
    </td>
</tr>
<tr class="top">
    <td style="width: 15%">Special Instructions</td>
    <td colSpan="3">
        <asp:textbox id="txtSpecialInstructions" Width="100%" Runat="server" Height="150" TextMode="MultiLine"/>
        <cc1:sqlinjectionvalidator id="sqlSpecialInstructions" runat="server" ControlToValidate="txtSpecialInstructions" ErrorMessage="Error in input field"/>
    </td>
</tr>
<tr>
    <td class="BoxHeader" colspan="4">Notification Information</td>
</tr>
<tr>
    <td class="nowrap" style="width: 15%">Requesting Branch</td>
    <td style="width: 35%">
        <asp:TextBox ID="txtRequestingBranch" runat="server" MaxLength="4"/><br/>
        <cc1:SqlInjectionValidator ID="sqlRequestingBranch" runat="server" ErrorMessage="Error in input field" ControlToValidate="txtRequestingBranch" />
    </td>
    <td class="nowrap" style="width: 15%">Requestor</td>
    <td style="width: 35%">
        <asp:TextBox ID="txtRequestor" runat="server" MaxLength="30"/><br/>
        <cc1:SqlInjectionValidator ID="sqlRequestor" runat="server" ErrorMessage="Error in input field" ControlToValidate="txtRequestor"/>
    </td>
</tr>
<tr>
    <td class="nowrap" style="width: 15%">IS Contact&nbsp;<asp:label ID=lblContactRequired runat=server cssclass="Required" Text="*"/></td>
    <td style="width: 35%">
        <asp:TextBox ID="txtContact" runat="server" MaxLength="30"/><br/>
        <asp:CustomValidator ID="cvContact" runat="server" Display="Dynamic" ControlToValidate="ddlPlatform" ErrorMessage="Required" />
        <cc1:SqlInjectionValidator ID="sqlContact" runat="server" ErrorMessage="Error in input field" ControlToValidate="txtContact" />
    </td>
    <td class="nowrap" style="width: 15%">Branches</td>
    <td style="width: 35%">
        <asp:TextBox ID="txtBranches" runat="server" MaxLength="50"/><br/>
        <cc1:SqlInjectionValidator ID="sqlBranches" runat="server" ErrorMessage="Error in input field" ControlToValidate="txtBranches" />
    </td>
</tr>
<tr>
    <td class="nowrap" style="width: 15%">Default Names</td>
    <td colspan="3">
        <asp:DropDownList ID="ddlSendToNames" runat="server" DataTextField="Description" DataValueField="Description"/>
        &nbsp;<input type="button" id="btnAddName" value="Add name" runat="Server" name="btnAddName"  onclick="addSendToName();" />
    </td>
</tr>
<tr>
    <td class="nowrap" style="width: 15%">Send Notice To&nbsp;<asp:label ID=lblSendToRequired runat=server cssclass="Required" Text="*"/></td>
    <td colspan="3">
        <asp:TextBox ID="txtSendNoticeTo" runat="server" Width="100%" TextMode="MultiLine" Height="120" />
        <asp:CustomValidator ID="cvSendNoticeTo" runat="server" Display="Dynamic" ControlToValidate="ddlPlatform" ErrorMessage="Required" />
        <cc1:SqlInjectionValidator ID="sqlSendNoticeTo" runat="server" ErrorMessage="Error in input field" ControlToValidate="txtSendNoticeTo"/>
    </td>
</tr>
</table>

コードビハインド:

Public Class ProjectInformation
Inherits System.Web.UI.UserControl


#Region "Attributes"
Private myPackage As ProjectPackage
#End Region

#Region "events"
''' <summary>
''' transfer the page over to the change notice report
''' </summary>
''' <remarks>
''' </remarks>
Protected Sub btnChangeNotice_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnChangeNotice.Click
    Dim queryString As New StringBuilder
    queryString.Append("reportloader.aspx?")
    queryString.Append(QUERYSTRING_REPORT).Append("=")
    queryString.Append(REPORT_NAME_CHANGENOTICE)
    'queryString.Append("&").Append(QUERYSTRING_PARAMETER).Append("=").Append(CType(Me.Parent.FindControl("txtPackageId"), TextBox).Text)
    queryString.Append("&").Append(QUERYSTRING_PARAMETER).Append("=").Append(myPackage.PackageId)
    queryString.Append("&").Append(QUERYSTRING_FORMAT).Append("=")
    queryString.Append(REPORT_FORMAT_ACROBAT)

    Response.Redirect(queryString.ToString, True)
End Sub

Protected Sub cvContact_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvContact.ServerValidate
    Dim pt As String = CType(Parent.FindControl("ddlProjectType"), DropDownList).SelectedValue

    If pt.ToLower.Equals("chg") And txtContact.Text.Equals(String.Empty) Then
        args.IsValid = False
    Else
        args.IsValid = True
    End If
End Sub

Private Sub cvDescription_ServerValidate(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvDescription.ServerValidate
    args.IsValid = CBool(txtDescription.Text.Length > 0)
End Sub

Protected Sub cvSendNoticeTo_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvSendNoticeTo.ServerValidate
    Dim pt As String = CType(Parent.FindControl("ddlProjectType"), DropDownList).SelectedValue

    If pt.ToLower.Equals("chg") And txtSendNoticeTo.Text.Length = 0 Then
        args.IsValid = False
    Else
        args.IsValid = True
    End If
End Sub

Private Sub cvTitle_ServerValidate(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvTitle.ServerValidate
    args.IsValid = CBool(txtTitle.Text.Length > 0)
End Sub
#End Region

#Region "Functions"
Private Sub BindData()
    BindPlatform()
    BindSystems()
    BindSendToNames()
End Sub

Private Sub BindPlatform()
    Dim pl As New BusinessLayer.PlatformCollection
    pl.Load()

    ddlPlatform.DataSource = pl
    ddlPlatform.DataTextField = "Description"
    ddlPlatform.DataValueField = "PlatformId"
    ddlPlatform.DataBind()

    ddlPlatform.Items.Insert(0, "")

    Try
        ddlPlatform.SelectedValue = myPackage.Platform.PlatformId
    Catch ex As Exception
        ddlPlatform.Items.Clear()
        ddlPlatform.Items.Insert(0, New Web.UI.WebControls.ListItem("Select Platform", ""))
        ddlPlatform.SelectedIndex = 0
    End Try
End Sub

Private Sub BindSendToNames()
    Dim st As New BusinessLayer.SendToCollection
    st.Load()

    ddlSendToNames.DataSource = st
    ddlSendToNames.DataBind()
End Sub

Private Sub BindSystems()
    Dim sm As New SystemManagerCollection
    sm.Load()

    ddlSystem.DataSource = sm
    ddlSystem.DataTextField = "Name"
    ddlSystem.DataValueField = "ManagerId"
    ddlSystem.DataBind()

    ddlSystem.Items.Insert(0, "")

    Try
        ddlSystem.SelectedValue = myPackage.SystemManager.ManagerId
    Catch ex As Exception
        ddlSystem.Items.Clear()
        ddlSystem.Items.Insert(0, New Web.UI.WebControls.ListItem("Manager not found", ""))
        ddlSystem.SelectedIndex = 0
    End Try
End Sub

''' <summary>
''' used to set permissions on the controls
''' </summary>
''' <remarks>
''' </remarks>
Public Sub DisableControls()
    myPackage = CType(Context.Session(SESSION_PACKAGE), ProjectPackage)
    Dim bum As New SystemManager
    bum.LoadBackUpManagerByManager(myPackage.SystemManager.ManagerId)

    If myPackage.SystemManager.ManagerId.ToLower.Equals(Context.User.Identity.Name.ToLower) Or _
       bum.ManagerId.ToLower.Equals(Context.User.Identity.Name.ToLower) Then
        If (myPackage.Status.Id = PackageStatusEnum.ReadyForManager Or _
           myPackage.Status.Id = PackageStatusEnum.DeniedForManager) Then
            ddlPlatform.Enabled = False
            ddlSystem.Enabled = False
            txtApplication.Enabled = False
            txtMenu.Enabled = False
            txtMenuStep.Enabled = False
            txtTitle.Enabled = False
            txtSpecialInstructions.Enabled = False
        Else
            ddlPlatform.Enabled = False
            ddlSystem.Enabled = False
            txtApplication.Enabled = False
            txtMenu.Enabled = False
            txtMenuStep.Enabled = False
            txtDescription.Enabled = False
            txtTitle.Enabled = False
            txtSpecialInstructions.Enabled = False
        End If

    Else
        ddlPlatform.Enabled = False
        ddlSystem.Enabled = False
        txtApplication.Enabled = False
        txtMenu.Enabled = False
        txtMenuStep.Enabled = False
        txtTitle.Enabled = False
        txtDescription.Enabled = False
        txtSpecialInstructions.Enabled = False
    End If

    ' notification section
    txtRequestingBranch.Enabled = False
    txtRequestor.Enabled = False
    txtContact.Enabled = False
    txtBranches.Enabled = False
    ddlSendToNames.Enabled = False
    btnAddName.Disabled = True
    txtSendNoticeTo.Enabled = False
End Sub

''' <summary>
''' unlock the controls that change control is able to update
''' </summary>
''' <remarks>
''' </remarks>
Public Sub EnableControlsForChangeControl()
    txtTitle.Enabled = True
    txtDescription.Enabled = True
    txtSpecialInstructions.Enabled = True
    ' notification section
    ddlSendToNames.Enabled = True
    btnAddName.Disabled = False
    txtSendNoticeTo.Enabled = True
End Sub

''' <summary>
''' unlock all controls for the package manager
''' </summary>
''' <remarks>
''' </remarks>
Public Sub EnableControlsForManager()
    ddlPlatform.Enabled = True
    ddlSystem.Enabled = True
    txtApplication.Enabled = True
    txtMenu.Enabled = True
    txtMenuStep.Enabled = True
    txtTitle.Enabled = True
    txtDescription.Enabled = True
    txtSpecialInstructions.Enabled = True
    txtContact.Enabled = True
    txtBranches.Enabled = True
    txtSendNoticeTo.Enabled = True
End Sub

''' <summary>
''' overridden function to load all of the form variables for the control
''' </summary>
''' <remarks>
''' </remarks>
Public Shadows Sub Load()
    myPackage = CType(Context.Session(SESSION_PACKAGE), ProjectPackage)

    BindData()
    SetFormVars()

    btnChangeNotice.Visible = CBool(myPackage.Status.Id > PackageStatusEnum.ReadyForManager)
End Sub

''' <summary>
''' toggle visibility of required field markers
''' </summary>
''' <param name="Required">required indicator</param>
''' <remarks>
''' </remarks>
Public Sub RequireNotification(ByVal Required As Boolean)
    lblSendToRequired.Visible = Required
    lblContactRequired.Visible = Required
End Sub

''' <summary>
''' set the values of the controls with the package and project information
''' </summary>
''' <remarks>
''' </remarks>
Private Sub SetFormVars()
    txtApplication.Text = myPackage.Application
    txtMenu.Text = myPackage.Menu
    txtMenuStep.Text = myPackage.MenuStep
    txtTitle.Text = myPackage.Title
    txtDescription.Text = myPackage.Description
    txtSpecialInstructions.Text = myPackage.SpecialInstructions

    myPackage.Project.Load()
    txtRequestingBranch.Text = myPackage.Project.RequestingLocation
    txtRequestingBranch.Enabled = False
    txtRequestor.Text = myPackage.Project.RequestorName
    txtRequestor.Enabled = False
    txtContact.Text = myPackage.Contact
    txtBranches.Text = myPackage.Branches
    txtSendNoticeTo.Text = myPackage.SendNoticeTo
End Sub

''' <summary>
''' update the project package with the data contained within this module
''' </summary>
''' <remarks>
''' </remarks>
Public Sub Update()
    myPackage = CType(Context.Session(SESSION_PACKAGE), ProjectPackage)

    If myPackage.Status.Id >= PackageStatusEnum.ReadyForDirector Then Exit Sub

    myPackage.Platform.PlatformId = ddlPlatform.SelectedValue
    myPackage.SystemManager.ManagerId = ddlSystem.SelectedValue
    myPackage.Application = txtApplication.Text
    myPackage.Menu = txtMenu.Text
    myPackage.MenuStep = txtMenuStep.Text
    myPackage.Title = txtTitle.Text
    myPackage.Description = txtDescription.Text
    myPackage.SpecialInstructions = txtSpecialInstructions.Text
    myPackage.Contact = txtContact.Text
    myPackage.Branches = txtBranches.Text
    myPackage.SendNoticeTo = txtSendNoticeTo.Text
    myPackage.UpdateInformation(Context.User.Identity.Name)

    'If ddlSendToNames.Enabled Then
    '    'myPackage.Project.RequestingLocation = txtRequestingBranch.Text
    '    'myPackage.Project.RequestorName = txtRequestor.Text
    '    myPackage.Contact = txtContact.Text
    '    myPackage.Branches = txtBranches.Text
    '    myPackage.SentNoticeTo = txtSendNoticeTo.Text
    '    myPackage.Project.UpdateNotificationInfo()
    'End If
    Context.Session(SESSION_PACKAGE) = myPackage
End Sub
#End Region

#Region "Properties"
'Public Property Package() As BusinessLayer.ProjectPackage
'    Get
'        Return myPackage
'    End Get
'    Set(ByVal Value As BusinessLayer.ProjectPackage)
'        myPackage = Value
'    End Set
'End Property

Public ReadOnly Property Platform() As String
    Get
        Return ddlPlatform.SelectedValue
    End Get
End Property

Public ReadOnly Property SystemManager() As String
    Get
        Return ddlSystem.SelectedValue
    End Get
End Property

Public ReadOnly Property ApplicationName() As String
    Get
        Return txtApplication.Text
    End Get
End Property

Public ReadOnly Property Menu() As String
    Get
        Return txtMenu.Text
    End Get
End Property

Public ReadOnly Property MenuStep() As String
    Get
        Return txtMenuStep.Text
    End Get
End Property

Public ReadOnly Property Title() As String
    Get
        Return txtTitle.Text
    End Get
End Property

Public ReadOnly Property Description() As String
    Get
        Return txtDescription.Text
    End Get
End Property

Public ReadOnly Property SpecialInstructions() As String
    Get
        Return txtSpecialInstructions.Text
    End Get
End Property
#End Region

End Class
4

1 に答える 1

0

関数を次のように変更します。

function addSendToName() {

    var textField = document.getElementById('<%= txtSendNoticeTo.ClientID %>');
    //      alert(document.getElementById(textFieldId));

    if (textField.value.length > 0) {
        textField.value += "; " + document.getElementById('<%= ddlSendToNames.ClientID %>').value;
    } else {
        textField.value = document.getElementById('<%= ddlSendToNames.ClientID %>').value;
    }
}

これらの名前は以前のコードで機能していた可能性がありますが、変更したため、ブラウザーが新しい/異なる名前を生成している可能性があります。このように記述すると、DOM で常に正しい ID を取得できます。

于 2013-08-07T16:36:38.947 に答える