onsdag den 9. december 2009

Changing control names on postback

I recently spent a whole day figuring out why my UserControl continuesly displayed inline errormessages instead of the validation summary I did tell it to use.

After af lot of investigation I found out that the controls in my UserControl did have changing control names upon postback due to inserted into sitecore placeholder.

I have failed to reproduce this scenario in a controlled matter but did find a fix to the problem.

Find the control that changes name upon postback and use this implementation of the sitecore placeholder.


 public class SCPlaceholder : Sitecore.Web.UI.WebControls.Placeholder  
   {  
     private List UsedKeys = System.Web.HttpContext.Current.Items["pckeys"] as List;  
     public SCPlaceholder()  
     {  
       if (UsedKeys == null)  
       {  
         UsedKeys = new List();  
         System.Web.HttpContext.Current.Items["pckeys"] = UsedKeys;  
       }  
     }  
     protected override void AddedControl(System.Web.UI.Control control, int index)  
     {  
       Sublayout s = control as Sublayout;  
       if (s != null && s.Controls.Count == 1)  
       {  
         string name = this.Key + "_" + s.Controls[0].GetType().Name;  
         if (UsedKeys.Contains(name))  
         {  
           for (int i = 0; i < 5; i++)  
           {  
             if (!UsedKeys.Contains(name + "_" + i))  
               name += "_" + i;  
           }  
         }  
         s.ID = name + "_sub";  
         s.Controls[0].ID = name;  
         UsedKeys.Add(name);  
       }  
       base.AddedControl(control, index);  
     }  
   }   

Experiences on how to reproduce this in a safe and clean environment is appreciated.

onsdag den 14. oktober 2009

Me and sitecore

This blog exists because I have a love/hate relationship with the CMS created by Sitecore which is a big part of my job as a web developer in Netmester A/S in Denmark.

I am always challeging Sitecore and Sitecore unfornunately often breaks to all the weird stuff Im doing to it every day.

Ill create blogs about all the weird stuff I meet and struggles to solve every day.

And this is the first in many.

Im at the moment developing a solution in Sitecore 6.1.0 which is currently the latest Sitecore release (not recommended version).

One of the new things in Sitecore 6 is that all security (rights, roles and other membership related stuff) are implemented using standard asp.net security rather than using Sitecores own security.
This should in itself be an approvement but sitecore has for one thing decided to implement the Sitecore domain functionality as part of the username which I personally think is pretty stupid.

Im using a third party member system that supplies users to the website (username, email, name etc).

In order to be able to log out this user, after login, using FormsAuthentication.SignOut() the user NEEDS to be added to the asp.net
Membership and therefore is visible in Sitecore security editor. With more than 5000 users this makes the security editor a bit crowded.
In order to put the users in a customer specific domain I need to prefix the user with the domain name followed by a backslash (\)
This makes it hard to map the sitecore user with the third pary member system or at least makes it more complicated because I now need to remove
the domain name from the sitecore user or append the domain name to the third party username.

Faste læsere