Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
User Control NAme: PreOrderControl.ascx
Code Behind: PreOrderControl.ascx.cs

My user control is like:

XML
<asp:TextBox ID="_txtLeadDate" runat="server" ReadOnly="true"></asp:TextBox>
    <asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="_txtLeadDate" ErrorMessage="You cannot select a day earlier than today!" OnServerValidate="CustomValidator2_ServerValidate" SetFocusOnError="True">&nbsp;</asp:CustomValidator>



and the server side code is:

C#
protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
    {



        if (some condition)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }


    }


But the page is showing error:

'ASP.usercontrol_preordercontrol_ascx' does not contain a definition for 'CustomValidator2_ServerValidate' and no extension method 'CustomValidator2_ServerValidate' accepting a first argument of type 'ASP.usercontrol_preordercontrol_ascx' could be found (are you missing a using directive or an assembly reference?)


Kindly help.
Posted
Updated 6-Jan-15 2:48am
v3
Comments
ZurdoDev 6-Jan-15 7:57am    
You may need to remove the protected keyword. I find letting the designer create the method easier than trying to remember the exact signature.
Mahatma Aladdin 6-Jan-15 7:59am    
tried that. Same error.
Tejas Vaishnav 6-Jan-15 8:17am    
Your custom validator and text box are on some user control? and your server side validation method is defined on your Aspx page?
Mahatma Aladdin 6-Jan-15 8:22am    
NO. everything here I have written are in user control. both asp:controls and the .cs code.
DamithSL 6-Jan-15 8:40am    
you need to provide the full name of user control, name of cs file, namespace of cs file, how you set your cs file in your user control file etc..

1 solution

you may have renamed your user control but haven't updated ascx file references accordingly. for example
ASP.NET
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PreOrderControl.ascx.cs" Inherits="MyApp.PreOrderControl" %>

and your PreOrderControl.ascx.cs file would be like below,
C#
namespace MyApp
{
    public partial class PreOrderControl : System.Web.UI.UserControl
    {

note the CodeBehind in ascx file and the Inherits properties, they should match with the file name and the class name with your namespace
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900