Layout form using C # for web part in sharepoint

I created a web part in C # for sharepoint. basically it is a form with text fields, literals, validators and buttons.

im not sure how to make this shape so that it looks beautiful. Layout etc. Fully executed inside this C # class.

At the moment, to get started, I'm just luring the CreateChildControls() method and adding each control with something like: this.Controls.Add(submitButton);

any ideas on how best to post this form?

Thanks.

+4
source share
5 answers

When creating my own web pages, I also prefer to implement them by overriding the CreateChildControls () and Render () methods. In the Render () method, I have complete control over the html output, and I can display my internal controls by calling this.someInnerControl.RenderControl (writer) .

Full control over html output also simplifies html style with CSS. As other people suggest, use an external CSS file and apply styles to the class attribute on the html elements or CssClass property in ASP.NET web control.

When I implement websites that do not require special branding, I prefer to reuse the CSS classes defined by SharePoint. This ensures that my website visually resembles the web page provided by SharePoint and that I maintain a consistent look.

When using the CSS styles defined by SharePoint, you should be aware of your html output. Some CSS classes require a special html structure for proper rendering. You can always use Source View browsers to check the html of the SharePoint element that you are trying to simulate.

+3
source

I would recommend grabbing the source from the existing sharepoint page and use the styles defined by sharepoint. This link to styles in 2003 is an old but still good guide to get you started. Most CSS class names have not changed.

+1
source

In my web parts, I include the css files in the solution and paste them into the page using something like:

 this.Page.Header.RegisterCss("/_layouts/path/to/css/file.css", false); 
0
source

You can override the RenderContents (...) method to manually render the HTML anyway. This includes adding any css inclusions, scripts, etc. that you want / use.

You can display child controls in rows and then output them as well, but you probably should NOT call the base.RenderContents (...) method.

Just make sure you remember to visualize your child controls.

0
source

If it’s important for you to see how you are designing, use SmartPart , which embeds the user control in the web part. (In case you did not know, user controls can be created using tools in Visual Studio.)

If you prefer manual code, then you're on the right track. Just create and set the initial properties for your controls in CreateChildControls () and use this.Controls.Add () as you were.

In both cases, where possible, use the CssClass property so that you can tinker with the appearance in the CSS file without having to recompile. You can hardcode the CSS class names, but it would be better to use the properties of the web part or an external configuration source to store them. Have a link to the CSS file on the main page or enter it on the page using the other methods mentioned in this answer.

MSDN Articles Web Parts in Windows SharePoint Services or Creating a Basic Web Part can also help.

0
source

All Articles