Need help creating custom Asp.Net 3.5 controls

I am looking for a link to instructions or walkthru to create custom controls in Asp.net 3.5.

I have already considered the following:

http://forums.asp.net/t/1385382.aspx : Including the .ascx user element in asp.net 3.5 Redistributable User Control

http://msdn.microsoft.com/en-us/library/aa479318.aspx : Including a .ascx user element in an asp.net 2.0 Redistributable User Control

I think the two links above are for Composite Custom Controls, which would be great at the moment, since it seems to be easier to make a Composite, rather than a complete user control.

Following the instructions in the link above (aa479318), I created the MyControl.ascx control file and published it, which was compiled into a standalone .dll, which was named App_Web_MyControl.ascx.cdcab7d2.

Then i put

<%Register Assembly="App_Web_MyControl.ascx.cdcab7d2" 
              TagPrefix="cc" namespace="TheNamespace" %> 

in the aspx file (in another application), where I wanted to use Custom Control, and add the link to the .dll assembly in the project.

CustomControl name is not recognized when trying to create it in .aspx code using

<cc:MyControl ID="idname" runat="server" />

I get an error. The 'MyControl' element is not a known element. ''

+3
source share
3 answers

It's already late, I know, but here it goes.

I have successfully turned UserSControl.ascx into a redistributable DLL by doing this:

  • ASP.NET - AscxDll
  • UserControl : ~/App_UserControls/RadioButtonQuestion.ascx.
  • - , " -":

  • VS cmd : aspnet_merge "C:\PrecompiledWebOutputDir\AscxDll" -o AssemblyName -r
  • AssemblyName.dll bin webapp/website, .
  • web.config \controls < tagPrefix = "MyPrefix" namespace = "ASP" assembly = "AssemblyName" / >
  • - : < MyPrefix: app_usercontrols_radiobuttonquestion_ascx ID = "rbq1" runat = "server" QuestionText = " aspx" / >

, web.config, namespace = "ASP" , - < MyPrefix: app_usercontrols_radiobuttonquestion_ascx/ > ; , ?

, , . , , .

, -.

+2

, UserControl, web.config. , , , DLL App_Web_MyControl.ascx.cdcab7d2.

, , - ...

<?xml version="1.0"?>

<configuration>

  <system.web>

    <pages>
      <controls>
        <add tagPrefix="cc" assembly="App_Web_MyControl.ascx.cdcab7d2" tagName="MyControl"/>
      </controls>
    </pages>

  </system.web>

</configuration>

... , "MyControl".

- .NET Reflector, App_Web_MyControl.ascx.cdcab7d2 ( DLL ) , "MyControl". , , App_Web_MyControl

0

, :

"ASP.Net Server Control". , ( ServerControl):

[DefaultProperty("Text")]
[ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]
public class ServerControl1 : WebControl
{
    [Bindable(true)]
    [Category("Appearance")]
    [DefaultValue("")]
    [Localizable(true)]
    public string Text
    {
        get
        {
            String s = (String)ViewState["Text"];
            return ((s == null) ? "[" + this.ID + "]" : s);
        }

        set
        {
            ViewState["Text"] = value;
        }
    }

    protected override void RenderContents(HtmlTextWriter output)
    {
        output.Write(Text);
    }
}

Then you can add fields, properties, and methods (public, private, or protected). If you do not want to override the RenderContents method, you can create a composite control by overriding the CreateChildControls method (see this example ).

Check out the HtmlTextWriter class for more information on what to do in the RenderContents method described above.

0
source

Source: https://habr.com/ru/post/1726924/


All Articles