添加RequiredFieldValidator时,调用目标将抛出异常

时间:2012-08-20 10:43:41

标签: asp.net gridview requiredfieldvalidator

我的GridView:

<asp:GridView ID="MyGridView" runat="server" ShowFooter="true"
                                AutoGenerateColumns="False" Visible="True">
<Columns>
<asp:BoundField DataField="id" ItemStyle-HorizontalAlign="center"/>
<asp:BoundField DataField="fullName"  />
<asp:TemplateField HeaderText="situation>">
<ItemTemplate>
  <asp:DropDownList ID="dl_situation" runat="server">
   </asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField>
 <ItemTemplate>
         <asp:TextBox ID="tbNr" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>  
<asp:TemplateField HeaderText="Data">
<ItemTemplate>
 <asp:TextBox ID="tbDate" runat="server"></asp:TextBox>
 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
      ErrorMessage="*" ControlToValidate="tbDate">
   </asp:RequiredFieldValidator>
 </ItemTemplate>
</asp:TemplateField>     
</Columns>
</asp:GridView>

当我试图填充GridView它给了我错误

Uncaught Sys.WebForms.PageRequestManagerServerErrorException:     
Sys.WebForms.PageRequestManagerServerErrorException: Exception has been 
thrown by the target of an invocation. ScriptResource.axd:847
Error$create ScriptResource.axd:847
PageRequestManager$_createPageRequestManagerServerError ScriptResource.axd:765
PageRequestManager$_parseDelta ScriptResource.axd:1654
PageRequestManager$_onFormSubmitCompleted ScriptResource.axd:1415
$type.createDelegate ScriptResource.axd:628
$type.getHandler ScriptResource.axd:4338
raise ScriptResource.axd:7248
WebRequest$completed ScriptResource.axd:7252
Sys.Net.XMLHttpExecutor._onReadyStateChange

在页面上的资源中,此错误位于此处

$type.create = function Error$create(message, errorInfo) {
    /// <summary locid="M:J#Error.create">Use this method to create a new error.   
   </summary>
    /// <param name="message" type="String" optional="true" mayBeNull="true">
     The error message.</param>
    /// <param name="errorInfo" optional="true" mayBeNull="true">
   A plain JavaScript object that contains extended information about the error.  
    The object should have a 'name' field that contains a string that identifies 
 the error   and any additional fields that are necessary to fully describe 
 the error.</param>
    /// <returns type="Error">An Error object.</returns>
    var e = Function._validateParams(arguments, [
        {name: "message", type: String, mayBeNull: true, optional: true},
        {name: "errorInfo", mayBeNull: true, optional: true}
    ]);
    if (e) throw e;

    var err = new Error(message);
**Uncaught Sys.WebForms.PageRequestManagerServerErrorException: 
Sys.WebForms.PageRequestManagerServerErrorException: 
 Exception has been thrown by the target of an invocation.**
    err.message = message;

    if (errorInfo) {
        for (var v in errorInfo) {
            err[v] = errorInfo[v];
        }
    }

    err.popStackFrame();
    return err;
}

1 个答案:

答案 0 :(得分:4)

我遇到了同样的问题并通过将 ClientIDMode =“AutoID”添加到GridView ItemTemplate中的验证器来解决了这个问题。