locked
custom control RRS feed

  • Question

  • User-88093336 posted

    when i register my custom control on the second line of the aspx page, the first line gives me error that name space in the imports doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.??????????

    Wednesday, March 17, 2010 5:36 PM

All replies

  • User1408790675 posted

    can you post your codes?

    Thursday, March 18, 2010 12:05 AM
  • User-1747586707 posted

    What imports does the error message mention? Do you use those imports any where, in your custom controls?

    Thursday, March 18, 2010 1:55 PM
  • User-88093336 posted

    I used the default imports as they showing once i created the custom control file, also i tried to remove them and all my attempts

    i got the same exact result, so the problem is (unable to register the custom control)?


    Thursday, March 18, 2010 4:09 PM
  • User-1747586707 posted

    Hm, probably there's something in your custom control.

    1) How do you create the custom control?

    2) Do you encounter the error with every custom control that you've created and registered?

    3) Does buiding the project make the error go away?

    Thursday, March 18, 2010 8:03 PM
  • User-88093336 posted
    • Right click on the  the App_Code folder (if it isn't in your website, in Solution Explorer, right_click on your website, click on 'Add ASP.NET folder', and Then App_Code)
    • Click 'Add New Item'
    • Click on Class, Select Language C#, Change the name to UserParameter.cs and click Add
    • Copy and paste this:
    1. namespace CustomControls  
    2. {  
    3.      /// <summary>  
    4.      /// Summary description for UserParameter  
    5.      /// </summary>  
    6.      public class UserParameter : System.Web.UI.WebControls.Parameter  
    7.      {  
    8.          protected override object Evaluate(HttpContext context, System.Web.UI.Control control)  
    9.          {  
    10.              if (context.User != null && !string.IsNullOrEmpty(context.User.Identity.Name))  
    11.              {  
    12.                  return context.User.Identity.Name;  
    13.              }  
    14.              return null;  
    15.          }  
    16.      }  
    17. }  
    • Save this file and close it.
    • In the page where you want to use this custom parameter control, add the following code at line 2:
    1. <%@ Register Namespace="CustomControls" TagPrefix="cc1" %>  
    • Finally, in the SelectParameter collection of your DataSource, Add
    1. <cc1:UserParameter Name="UserName" />


    I got same error in every time i used the code, my problem is it is not possible to register the custom control and get error even

    when i compile the code.

    Saturday, March 20, 2010 7:33 PM
  • User-1747586707 posted

    I don't see any compile error when doing what you've described.

    Here's the complete code  of UserParameter.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    /// Summary description for UserParameter
    /// </summary>
    
    namespace CustomControls  
    {  
         /// <summary>  
         /// Summary description for UserParameter  
         /// </summary>  
         public class UserParameter : System.Web.UI.WebControls.Parameter  
         {  
             protected override object Evaluate(HttpContext context, System.Web.UI.Control control)  
             {  
                 if (context.User != null && !string.IsNullOrEmpty(context.User.Identity.Name))  
                 {  
                     return context.User.Identity.Name;  
                 }  
                 return null;  
             }  
         }  
    }


    After adding the Register directive, inside <SelectParameters> tag, when typing  "<cc1:", do you see "cc1:UserParameter" listed in the intellisense list?

    Thursday, March 25, 2010 6:26 PM
  • User-88093336 posted

    Hello,

    I don't see this at all, even when i compile i get the error on the line of (cc1)

    Please help.

    Thursday, March 25, 2010 8:32 PM
  • User101908363 posted

    I got the same error message when I hover over the line of text you get this message.

    "Element 'UserParameter' is not a known element.  This can accur if there is a compilation error in the web site, or the web.config file is missing."

    Thursday, May 2, 2013 2:34 PM