.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Custom controls

Posted By:nishithraj       Posted Date: November 27, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  
 

Here is an example for the customcontroller in aspx page. It can be accessed by the <%@ Register %>with a tagprefix. Visual studio will generate the <%@ Register %>with a tagprefix at the time of dragging the control to the aspx page. Mostly with the letters "cc": cc1, cc2, etc. Also it provides the inheriting name spaces too.

Here in the sample the ControlDesigner class exists in the name space System.Web.UI.Design.ControlDesigner


using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;

namespace Sample.CustomControl {

public class SampleDesignerCls : ControlDesigner {

public SampleDesignerCls () {
}

public override string GetRunTimeDesign() {

// Following is the run time object for the ControlDesigner class
Simple SmpDesignerComponent = (Simple) Component;

StringWriter sw = new StringWriter();
// HtmlTextWriter is used to write the run time html to be rendered
HtmlTextWriter tw = new HtmlTextWriter(sw);

HyperLink lnkAtPlaceHolder = new HyperLink();

// Making the control text as the link's text
lnkAtPlaceHolder.Text = SmpDesignerComponent.Text;
lnkAtPlaceHolder.RenderControl(tw);

return sw.ToString();
}
}
}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend