Similarities
Advantage of Web Parts
Advantage of Controls
SharePoint also uses custom WebControls a lot. Some examples ("<" and "/>" tags have been removed from beginning and end of each line):
To create a custom Control:
To use the custom Web Control:
Some tips from the MSDN article "Walkthrough: Developing and Using a Custom Server Control" :
Sample code: following code adds current web's Title as content of Keywords Meta Tag
public class CustomMetaTag : WebControl {
protected override HtmlTextWriterTag TagKey {
get { return HtmlTextWriterTag.Meta; }
}
protected override void AddAttributesToRender(HtmlTextWriter writer) {
base.AddAttributesToRender(writer);
writer.AddAttribute(HtmlTextWriterAttribute.Name, "keywords");
SPWeb web = SPControl.GetContextWeb(Context);
writer.AddAttribute(HtmlTextWriterAttribute.Content, web.Title);
Note: a very good example of using a custom WebControl is given in this blog entry by Waldek Mastykarz -> Extending the SharePoint:FieldValue WebControl
PingBack from http://sovit.biz/vedants-blog-using-custom-aspnet-controls-in-sharepoint-2007/
Hi Vedant, I have a question: When I try to add a server control to the SPD design surface I get the following error: "Error rendering control Control1 - An error occurred while fetching preview"
I am using SPD in MOSS and am logged in as domain admin.
I have made the change in Local Security policy to allow Authenticated Users to Bypass Traverse Checking (as per Mike Walshs commenst)
Any suggestion would be greatly appreciated as this is has halted a live development project.
Regards
Gary
Hi Vedant,
Any idea, how different it is in SP 2010?
I have created a control, deployed and kept it on a master page. In SPD I see the control, but not in the browser. Can you give an insight on this?
Thanks bro.
You don't know what you have done to me!:D
>:D<