选中后,组合框选定的项目将被删除。无效的回发或回调参数

时间:2012-06-05 09:34:45

标签: c# asp.net

我的页面中有四个文本框,一个组合框和一个按钮(以及一些其他控件)。根据文本框中键入的值,相关值将在组合框中更新。单击我页面中的提交按钮时出现以下错误。

  
    

"无效的回发或回调参数。使用配置或页面启用事件验证。出于安全目的,此功能将验证回发或回调事件的参数是否来自最初呈现它们的服务器控件。如果数据有效且预期。使用ClientScriptManager.RegisterForEventsValidation方法注册回发或回调数据以进行验证。"

  

现在在页面指令中我添加了

<%@Page EnableEentValidation="false"> 

当我在四个文本框中键入值时,相应的值将出现在cobobox中。但是当我选择组合框值时,将删除所选值。这是什么原因?

<%@ Page Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="AddeChecklist.aspx.cs"
    Inherits="LabTrack.WebApplication.Echecklist.AddeChecklist" EnableEventValidation ="false" %>

<%@ Register TagPrefix="Labinal" TagName="AutoCompleteControl" Src="~/UserControls/AutoCompleteEnabledWebUserControl.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../Styles/CheckListRev.css" rel="stylesheet" type="text/css" />
    <!-- Style for the page -->
    <link href="../Styles/AddeChecklist.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">
    </asp:ScriptManager>
    <asp:Panel ID="ErrorMessagePanel" CssClass="ErrorPanel" Visible="true" runat="server">
        <div class="ErrorDiv">
            <asp:BulletedList CssClass="ErrorMessage" ID="ErrorMessageBulletedList" runat="server">
            </asp:BulletedList>
        </div>
    </asp:Panel>
    <div class="PageTitle">
        <asp:Label ID="PageHeaderLabel" runat="server"></asp:Label>
    </div>
    <div class="MainDiv">
        <div style="text-align: center;">
            <div class="PlaceHolder">
                <table id="formTable">
                    <tr>
                        <td>
                            <asp:UpdatePanel runat="server" ID="updatepanelCustomer" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <span class="boldLabelLong">Customer:</span><br />
                                    <asp:TextBox ID="CustomerNameTextBox" Width="200" runat="server"></asp:TextBox>
                                    <asp:HiddenField ID="IxCustomerHiddenField" runat="server" />
                                    <asp:Button ID="customerTriggerbutton" runat="server" Text="Button" Style="display: none;" />
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </td>
                        <td>
                            <asp:UpdatePanel runat="server" ID="updatepanelProgram" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <span class="boldLabelLong">Program:</span><br />
                                    <asp:TextBox ID="ProgramNameTextBox" Width="200" runat="server"></asp:TextBox>
                                    <asp:Button ID="programTriggerbutton" runat="server" Text="Button" Style="display: none;" />
                                    <asp:HiddenField ID="IxProgramHiddenField" runat="server" />
                                </ContentTemplate>
                                <Triggers>
                                    <asp:AsyncPostBackTrigger ControlID="customerTriggerbutton" EventName="Click" />
                                </Triggers>
                            </asp:UpdatePanel>
                        </td>
                        <td>
                            <asp:UpdatePanel runat="server" ID="updatepanelWorkPackage" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <span class="boldLabelLong">WorkPackage:</span><br />
                                    <asp:TextBox ID="WorkPackageNameTextBox" Width="200" runat="server"></asp:TextBox>
                                    <asp:HiddenField ID="IxWorkPackageHiddenField" runat="server" />
                                    <asp:Button ID="workPackageTriggerbutton" runat="server" Text="Button" Style="display: none;" />
                                </ContentTemplate>
                                <Triggers>
                                    <asp:AsyncPostBackTrigger ControlID="programTriggerbutton" EventName="Click" />
                                </Triggers>
                            </asp:UpdatePanel>
                        </td>
                        <td>
                            <asp:UpdatePanel runat="server" ID="updatepanelActivity" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <span class="boldLabelLong">Activity:</span><br />
                                    <asp:TextBox ID="ActivityNameTextBox" Width="200" runat="server"></asp:TextBox>
                                    <asp:HiddenField ID="IxActivityHiddenField" runat="server" />
                                    <asp:Button ID="activityTriggerbutton" runat="server" Text="Button" Style="display: none;" />
                                </ContentTemplate>
                                <Triggers>
                                    <asp:AsyncPostBackTrigger ControlID="workPackageTriggerbutton" EventName="Click" />
                                    <asp:AsyncPostBackTrigger ControlID="activityTriggerbutton" EventName="Click" />
                                </Triggers>
                            </asp:UpdatePanel>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="PlaceHolder">
                <asp:Label ID="TemplateLabel" Text="Template:" CssClass="ControlLabel" runat="server"></asp:Label>
                <asp:UpdatePanel runat="server" ID="updatepanelTemplate" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:DropDownList ID="TemplateSelectDropDownList" runat="server" Width="400" Visible="true"
                            AutoPostBack="true">
                        </asp:DropDownList>
                        <asp:HiddenField ID="IxTemplateHiddenField" runat="server" />
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="workPackageTriggerbutton" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
                <asp:Panel ID="SustainPanelTemplateOwner" Visible="true" runat="server">
                    <div>
                        <asp:Label ID="TemplateOwnerLabel" Text="Owner:" CssClass="ControlLabel" runat="server"></asp:Label>
                        <asp:TextBox ID="TemplateOwnerTextBox" CssClass="controlMargin" Width="400" runat="server"></asp:TextBox>
                    </div>
                </asp:Panel>
                <asp:HiddenField ID="IxDeliverableHiddenField" runat="server" />
                <asp:HiddenField ID="IxReleaseActionHiddenField" runat="server" />
                <asp:HiddenField ID="IxConfigHiddenField" runat="server" />
                <asp:HiddenField ID="IxTemplateOwnerHiddenField" runat="server" />
                <asp:HiddenField ID="TemplateSelectedSnameHiddenField" runat="server" />
                <asp:HiddenField ID="TemplateOwnerSelectedsNameHiddenField" runat="server" />
                <asp:HiddenField ID="DeliverableSelectedHiddenField" runat="server" />
                <div>
                    <asp:Label ID="DeliverableLabel" CssClass="ControlLabel" runat="server" Text="Deliverable:"></asp:Label>
                    <asp:TextBox ID="DeliverableTextBox" CssClass="controlMargin" Width="400" runat="server"></asp:TextBox>
                </div>
                <asp:Panel ID="SustainPanelConfig" Visible="true" runat="server">
                    <div>
                        <asp:Label ID="ConfigurationLabel" runat="server" Text="Configuration:" CssClass="ControlLabel"></asp:Label>
                        <select id="ConfigurationSelect" class="controlMargin">
                            <option></option>
                        </select>
                    </div>
                </asp:Panel>
                <asp:Panel ID="SustainPanelRelease" Visible="true" runat="server">
                    <div>
                        <asp:Label ID="ReleaseActionLabel" CssClass="ControlLabel" runat="server" Text="Release Action:"></asp:Label>
                        <asp:TextBox ID="ReleaseActionTextBox" CssClass="controlMargin" Width="400" runat="server"></asp:TextBox>
                    </div>
                </asp:Panel>
                <asp:Panel ID="SustainPanel" Visible="true" runat="server">
                    <div class="SustainPanelControls">
                        <div>
                            <asp:Label ID="ChangeLabel" Text="Change #: " runat="server"></asp:Label>
                        </div>
                        <div>
                            <asp:TextBox ID="ChangeTextBox" Width="110" runat="server"></asp:TextBox>
                        </div>
                        <div>
                            <asp:Label ID="SupplementLabel" Text="Supplement: " runat="server"></asp:Label>
                        </div>
                        <div>
                            <asp:TextBox ID="SupplementTextBox" Width="80" runat="server"></asp:TextBox>
                        </div>
                        <div>
                            <asp:Label ID="NewWrrLabel" Text="WRR #: " runat="server"></asp:Label>
                        </div>
                        <div>
                            <asp:TextBox ID="NewWrrTextBox" Width="80" runat="server"></asp:TextBox>
                        </div>
                        <div>
                            <asp:Label ID="DddLabel" Text="3D: " runat="server"></asp:Label>
                        </div>
                        <div>
                            <asp:TextBox ID="DddTextBox" Width="80" runat="server"></asp:TextBox>
                        </div>
                    </div>
                    <div>
                        <table id="DesignDataTable2">
                            <tr>
                                <td>
                                    <asp:Label ID="AllFbSheetsWrrLabel" Text="All F/B Sheets w/WRR #:" CssClass="ControlLabel" runat="server"></asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox CssClass="completeControl" ID="AllFbSheetsWrrTextBox" Width="588" Rows="2"
                                        TextMode="MultiLine" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                        </table>
                    </div>
                </asp:Panel>
            </div>
            <div class="EditButtonGroup">
                <input id="EditButton" type="button" value="Edit" class="ButtonSettings" />
                <input id="RemoveButton" type="button" value="-" class="ButtonSettings" />
                <input id="AddButton" type="button" value="+" class="ButtonSettings" />
            </div>
        </div>
        <div class="ViewData">
            <div class="ViewDataDiv">
                <table id="DesignDataTable" class="designDataTable">
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="submitButtonDiv">
            <asp:Button ID="SubmitButton" runat="server" Text="Button Text" class="submitButtonCreateChecklist" />
        </div>
    </div>
</asp:Content>

2 个答案:

答案 0 :(得分:1)

听起来像Viewstate覆盖值的问题。

尝试使用Request.Form[Dropdown.ClientId]

直接获取值

答案 1 :(得分:1)

您正在客户端创建新值,并将它们发布回服务器。

出于安全原因,ASP.NET实现了“事件验证”。启用甚至验证后,如果服务器创建具有3个可能值的组合,则它仅在回发时接受此值。如果您创建了不同的值并将其发送回服务器,则会收到您所指的错误。

这里有一些信息: Page.EnableEventValidation Property

如果您知道在客户端生成的可能值,可以使用ClientScriptManager.RegisterForEventValidation Method,如果您事先不知道,则可以完全禁用验证。

禁用验证:

  
    

通过在Web.config文件中设置@Page指令的enableEventValidation属性或pages元素的enableEventValidation属性来设置EnableEventValidation属性。如果在代码中设置此属性,则必须在初始化页面之前设置它。