Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Adding a Sharepoint.webcontrol to a web part

  Asked By: Cedric    Date: Mar 02    Category: Sharepoint    Views: 2427

I am trying to create a webpart that adds editing controls to the page
on the fly. I want to add a a UserField or a TextField object to the
page. In my webpart code I tried the following:

UserField uf = new UserField();
uf.FieldName = "person";
uf.ID = "userfieldxt";
uf.RenderControl(writer);

The code executes and doesn't throw any errors but the control is not
added to the page. This code is in the RenderContents method. I also
tried to add similar code to the createchildcontrols method with the
same result. The strange thing is that if I change the control to a
TextBox the code renders the text box no problem.

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Iris Ballard     Answered On: Mar 02

You need to instatiate the controls  in the CreateChildControls method.

Example:
cbxADSS = new CheckBox();
cbxADSS.AutoPostBack = true;
cbxADSS.Text = "Your text";
cbxADSS.Checked = false;
this.Controls.Add(cbxADSS);

 
Answer #2    Answered By: Jamila Guthrie     Answered On: Mar 02

I can get it working with a system.web.ui.webcontrol like a checkbox
or a text  box. What I am looking for is the editing  controls like a
UserField or rich text editor (TextField) that are
Microsoft.Sharepoint.webcontrols objects.

 
Answer #3    Answered By: Kalpana Ghatge     Answered On: Mar 02

Did you try wrapping these controls  within a .ascx control? If you render
the ascx control  within a web  part, you can take advantage of the VS 2005
GUI to design your controls.

FYI, if you add  a reference to Microsoft.SharePoint.dll to your .ascx
controls solution, you can add SharePoint controls to your toolbox (i.e.
SPGridView).

Some links on using .ascx controls:
jopx.blogspot.com/.../...ls-ascx-webparts-and.html
http://blog.mike-obrien.net/PermaLink,guid,77b4fc7b-c4a3-48da-bdc7-c0419d7cd0ca.\
aspx

 
Answer #4    Answered By: Davon Henson     Answered On: Mar 02

Try adding  the control  directly to the Controls collection of the page.

 
Didn't find what you were looking for? Find more on Adding a Sharepoint.webcontrol to a web part Or get search suggestion and latest updates.




Tagged: