all things Sitecore related


C#: Get Parent Control with Generics

By on April 27, 2010 in ASP.Net, C#, Controls with 0 Comments
C#: Get Parent Control with Generics

I use the following method to return a parent control of a specific type. This method is recursive and uses generics. <br /> private Control GetParentControl<T1>(Control control)<br /> {<br /> if (control.Parent.GetType() == typeof(T1))<br /> {<br /> return control.Parent;<br /> }<br /> else<br /> {<br /> return GetParentControl<T1>(control.Parent);<br /> }<br /> }</p> <p>

Continue Reading »

Create a Visual Studio add-in with contextmenu and selected text as input

By on February 25, 2010 in C#, Controls, Visual Studio with 0 Comments

Create a Visual Studio add-in with contextmenu and selected text as input When working with a new way of storing settings in a database. I was frustrated how much work it was to check the value of setting from code. So I deceided to make my life a bit easier by creating a VS2008 contextmenu […]

Continue Reading »

Asp.Net: DataPager problem with Listview

By on December 23, 2009 in ASP.Net, Controls with 2 Comments

When using the Datapager with a ListView I had the following problem. When clicking a paging button for the first time nothing happens.But when I click a button the second time, then the page from the first click loads. I search the internet for a solution and found that you need to add some code to […]

Continue Reading »

Add meta data (keywords, description) dynamicly

By on July 6, 2009 in ASP.Net, Controls with 1 Comment

Add meta-data dynamically to your page by adding a HtmlMeta control to your Header. In this example I dynamically add a keyword string to the page. string keyWords = "metatags, html, dynamic, generate"; HtmlMeta keywords = new HtmlMeta(); keywords.Name = "keywords"; keywords.Content = keyWords; Page.Header.Controls.Add(keywords);  You can do the same for other meta-data like description.

Continue Reading »

Using the ViewState within the SelectMethod of a ObjectDataSource

By on June 3, 2009 in ASP.Net, Controls with 1 Comment

By default it is not possible to use the ViewState within methods of a ObjectDataSource. Because the DataSource doesn’t run within the current page instance, it just fires the method that you specified. You can set the page instance for the DataSourceby setting the ObjectInstance property in the ObjectCreating event of the DataSource. <asp:ObjectDataSource ID="odsListing" […]

Continue Reading »

Asp.Net: Clear inputfields after form submit

By on April 15, 2009 in ASP.Net, Controls with 3 Comments

Every time a form is successful summited I need to clear all input-fields to the default values and give feedback to the user. I wrote a method ClearControl that can have a control as input parameter. This method will set the control based on his type back to the defaultvalue.  public static void ClearControl(Control control) {  switch (control.GetType().Name)  {   case "TextBox": […]

Continue Reading »

Sitecore: itemlist with ObjectDataSource, Listview and DataPager

By on April 8, 2009 in ASP.Net, Controls with 2 Comments

For a new project I started working with Sitecore again. I needed to create a listing of items with paging. I implemented a Listview with a ObjectDataSource and the DataPager control. <asp:ListView ID="lvListing" runat="server" DataSourceID="odsListing" onitemdatabound="lvListing_ItemDataBound">     <ItemTemplate>          <li class="clearfix">             <a class="thumb" ID="thumnailLink" runat="server" >                  <sc:Image Field="Thumbnail" ID="thumbnailImage" MaxWidth="120" runat="server" />             […]

Continue Reading »

Asp.Net: Charting Control (Error ChartImg.axd)

By on March 3, 2009 in ASP.Net, Controls, Microsoft with 3 Comments

After installing and playing with the Asp.Net Charting control I decided to use it for a customer. When integrating the control to the project I got the following error "Error executing child request for ChartImg.axd" This error occurred because I did not update my web.config file. You have to add the following appSettingkey, httpHandler and handler. [code:xml] <appSettings>     […]

Continue Reading »

Asp.Net: Menu control remove MenuItem (MenuItemDataBound)

By on February 26, 2009 in ASP.Net, Controls with 0 Comments

For a project I needed to remove menu items to the pages in the folder ‘Subscriberpages’ when a the user is in the Role of ‘Marketing’ and ‘AccountManagement’. To do this I added the following code to the MenuItemDataBound event. protected void mainMenu_MenuItemDataBound(object sender, MenuEventArgs e) {  SiteMapNode node = e.Item.DataItem as SiteMapNode;  if (node.Url.Contains("<em>Subscriberpages</em>"))  {   if […]

Continue Reading »

Asp.Net: Using the OnCommand Event with CommandArgument

By on February 4, 2009 in ASP.Net, Controls with 0 Comments

When using a button, linkbutton or imagebutton with CommandArguments or CommandName you can use the OnCommand event instead of the OnClick event. Using the OnCommand Event you use less code to extract the CommandArgument and CommandName from the Event comparing to the OnClick event (because you don’t need to cast the control). Code example The Aspx: <asp:ImageButton […]

Continue Reading »

Asp.Net: Databinding a array of strings

By on January 30, 2009 in ASP.Net, Controls with 0 Comments

You can use a string array as datasource and view the string values by using the Container.DataItem property. Code example Codebehind: [code:c#] string[] testData = {"1","two","3","4"}; rptDemo.DataSource = testData; rptDemo.DataBind(); [/code] And in the .aspx: [code:html] <asp:Repeater runat="server" ID="rptDemo">     <ItemTemplate>         <%# Container.DataItem %>     </ItemTemplate> </asp:Repeater> [/code]

Continue Reading »

Asp.Net : Setting the DefaultButton for the LoginControl

By on January 22, 2009 in ASP.Net, Controls with 0 Comments

You can set the DefaultButton property of the Login control by putting the Login control in a Panel and set the DefaultButton property of the panel to the LoginControlId$LoginButton. Code example: <asp:Panel ID="panelLogin" runat="server"             DefaultButton="Login1$LoginButton">       <asp:Login ID="Login1" runat="server" /> </asp:Panel> Cheers, Pieter

Continue Reading »

Some tips for the dropdown control

By on December 30, 2008 in ASP.Net, Controls with 0 Comments

I always have problems implementing the Asp.Net dropdown control. Here are some simple tips to make your life (with dropdown controls) easier. Adding an default item with data binded dropdown To add an default listItem to your data binded dropdown list you just have to add a ListItem on the first place (0) of your control […]

Continue Reading »

ListView: OnItemDataBound

By on July 23, 2008 in ASP.Net, Controls with 0 Comments

Get dataItem onItemDataBound (don't forget to replace the bold parts with your objectname): [code:c#] protected void MainPostListView_ItemDataBound(object sender, ListViewItemEventArgs e) { YourObject item = (YourObject)((ListViewDataItem)e.Item).DataItem; } [/code]   Findcontrol within the itemtemplate: [code:c#] HyperLink hplTitle = (HyperLink)e.Item.FindControl("hyperLink"); [/code]    

Continue Reading »

Asp.Net AJAX controltoolkit javascript funtions

By on June 25, 2008 in AJAX, Controls, Javascript with 0 Comments

I've search them all up for a 1000 times. Now I'm going to write them down as reference. This post will grow in the next few months. Remember do not forget to set the behaviorId of the control.  References: CollapsiblePanelExtender Expand: $find('BehaviorId')._doOpen(); Collapse: $find('BehaviorId')._doClose(); $find('BehaviorId').collapsePanel(); ModalPopupExtender Show popup: $find('BehaviorId').show(); Hide popup: $find('BehaviorId').hide(); 

Continue Reading »