SharePoint Blog - René Hézser

Anmelden  RSS Feed RSS Feed
Startet die Suche

Archive

Kategorien

Links

Andere Blogs



Add to Technorati Favorites

Aug 112009

Control.ClientID has wrong value

An ASP.NET Controls has a ClientID property. SharePoint Controls inherit from the ASP.NET Controls. The property will give you the ID, the rendered control will have in the HTML source. There is one thing to remember:

The ClientID is valid only, if the control has been added to the Controls of the Page!

ID before adding the control ID after adding the control
FilterButton ctl00_m_Webpart1_FilterButton

So if you need the ClientID e.g. to pass it to a JavaScript to be able to find the control, make sure you grab the ClientID after the control has been added to the Page.


Published: 8/11/2009  11:32 AM | 0  Comments | 0  Links to this post
Tagged as: Development, Web Controls

Jul 122009

Using SharePoint Controls

Back from vacation. 1 week with an offline version of feeds is hard. So I read the postings I got closely :-) One post I do want to bring your attention to, is about SharePoint Controls.

My post about using the SharePoint Controls shows how to use the controls you see in forms (TextField, NumberField, LookupField…).

There are plenty of SharePoint controls, which you can use. Robin Meure has written a post “re-using SharePoint controls”. The controls in his post are:

WebApplicationSelector image
SiteAdministrationSelector image
SchedulePicker image
SPDatePickerControl image
ButtonSection image
InputFormSection, InputFormControl image
InputFormTextBox image
InputFormRequiredFieldValidator image
InputFormRangeValidator image
ToolBar, ToolBarButton image

Go to his post to see the code on how to use these controls.

Update February 2010:

If you want to learn more about InputFormSection.ascx and InputFormControl.ascx Controls, you have to take a look at the post

InputFormSection.ascx and InputFormControl.ascx Controls over at Karine Bosch’s Blog.


Published: 7/12/2009  9:22 AM | 0  Comments | 0  Links to this post
Tagged as: Development, SharePoint, Web Controls

Feb 222009

How to use the SharePoint Web Controls – Update

My post How to use the SharePoint Web Controls has been updated.

It now shows how to use a generic control for each SPField, instead of picking the corresponding SharePoint Web Control.

   1:  BaseFieldControl webControl = field.FieldRenderingControl; 
   2:  webControl.ListId = list.ID; 
   3:  webControl.ItemId = item.ID; 
   4:  webControl.FieldName = field.Title;
   5:  webControl.ID = GetControlID(field);
   6:  webControl.ControlMode = mode;

Thanks for all the great comments and ideas!


Published: 2/22/2009  7:58 PM | 0  Comments | 0  Links to this post
Tagged as: Development, SharePoint, Web Controls

Jan 192009

SharePoint Web Controls to access remote content

In my post How to use the SharePoint Web Controls I talked about using the SharePoint Web Controls to show and edit data in SharePoint lists.

Today I want to post a sample how to work on a list, which is in another web. The remote list will be the "User Information List" which exists on every rootWeb.

   1:  // connect to the rootweb, to read the users list
   2:  var rootWeb = SPContext.Current.Site.RootWeb;
   3:  {
   4:      // get the current user and corresponding item in the user information list
   5:      SPUser user = SPContext.Current.Web.CurrentUser;
   6:      SPList list = rootWeb.Lists["User Information List"];
   7:      SPListItem userItem = list.GetItemById(user.ID);
   8:   
   9:      // set the context, so the controls will work
  10:      SPContext context = SPContext.GetContext(
  11:          HttpContext.Current, userItem.ID, list.ID, rootWeb);
  12:   
  13:      // Username
  14:      Controls.Add(new Label { Text = "Username:" });
  15:      var username = new TextField
  16:      {
  17:          ID = "Username",
  18:          FieldName = "Title",
  19:          ItemId = userItem.ID,
  20:          ListId = list.ID,
  21:          ControlMode = SPControlMode.Edit,
  22:          RenderContext = context,
  23:          ItemContext = context
  24:      };
  25:      Controls.Add(username);
  26:   
  27:      // about me
  28:      Controls.Add(new Label { Text = "About me:" });
  29:      var aboutMe = new RichTextField
  30:      {
  31:          ID = "AboutMe",
  32:          FieldName = "Notes",
  33:          ItemId = userItem.ID,
  34:          ListId = list.ID,
  35:          ControlMode = SPControlMode.Edit,
  36:          RenderContext = context,
  37:          ItemContext = context
  38:      };
  39:      Controls.Add(aboutMe);
  40:  }

The key point is to create a context, which is different from the current. This new context will be used by the SharePoint Web Controls to render data from the User Information List. The output would be something like this:

If you do not set the context for the controls and try to access data from another context (which you try if you specify the list from another web), you will get an InvalidOperationException.

Operation is not valid due to the current state of the object.

Technorati Tags: ,


Published: 1/19/2009  5:41 PM | 0  Comments | 1  Links to this post
Tagged as: Development, SharePoint, Web Controls