I am using telerik control (RAD menu) skin.We are creating the menu dynamically and applying skin at item_databound. When the page is loaded first time the skin is not being applied. When the page is refreshed everything seems to be working fine. Please suggest a solution.
///Applying Skin
protected override void CreateChildControls()
{
try
{
listname =
ConfigurationManager.AppSettings["sitemenulist"] ?? defaultSiteMenuList;
List<BallMenu> sitemenu = GetMenu();
if (sitemenu.Count == 0)
{
var lblMenu = new Label {Text = "No items found in " + listname};
Controls.Add(lblMenu);
}
else
{
var ballsiteroot = new RadMenu();
ballsiteroot.DefaultGroupSettings.OffsetY = 6;
ballsiteroot.Skin = vista;
ballsiteroot.EnableEmbeddedSkins =
false;
ballsiteroot.EnableTheming =
true;
ballsiteroot.ItemDataBound += ballsiteroot_ItemDataBound;
ballsiteroot.DefaultGroupSettings.ExpandDirection =
ExpandDirection.Down;
ballsiteroot.DefaultGroupSettings.RepeatColumns = 2;
ballsiteroot.DataTextField =
"Text";
ballsiteroot.DataNavigateUrlField =
"Url";
ballsiteroot.DataFieldID =
"ID";
ballsiteroot.DataFieldParentID =
"ParentID";
ballsiteroot.DataSource = sitemenu;
ballsiteroot.DataBind();
Controls.Add(ballsiteroot);
}
base.CreateChildControls();
}
catch (Exception ex)
{
Log.Error(
"Failed to create RadMenu control", ex);
throw;
}
}
///Creating menu item dynamically
private List<BallMenu> GetMenu()
{
int cacheTime;
if (!Int32.TryParse(ConfigurationManager.AppSettings["BallSitesCachetime"], out cacheTime))
{
cacheTime = defaultBallSitesCacheTime;
}
var gotostrut = new GotoMenu(listname);
List<BallMenu> sitemenu;
object cacheItem = HttpRuntime.Cache[strUserNamecache];
if (cacheItem == null)
{
sitemenu = gotostrut.GenerateSiteData();
HttpRuntime.Cache.Insert(strUserNamecache, sitemenu, null, DateTime.Now.AddMinutes(cacheTime), TimeSpan.Zero);
}
else
{
sitemenu = (
List<BallMenu>) cacheItem;
}
return sitemenu ?? new List<BallMenu>();
}
private void ballsiteroot_ItemDataBound(object sender,
RadMenuEventArgs e)
{
try
{
var head = (string) DataBinder.Eval(e.Item.DataItem, "Text");
string[] arr = head.Split(',');
if (arr.Length > 1)
{
if (arr[1] == "1")
{
if (arr[0] == " ")
{
e.Item.CssClass =
"Blue1";
e.Item.Text = arr[0];
e.Item.Enabled =
false;
e.Item.Width = 166;
}
else
{
e.Item.CssClass =
"Blue3";
FontInfo fontinfo = e.Item.Font;
fontinfo.Name =
"Verdana";
fontinfo.Bold =
true;
fontinfo.Size = 8;
e.Item.ForeColor =
Color.Black;
e.Item.Text = arr[0];
e.Item.Enabled =
false;
}
}
}
else
{
if ((int) DataBinder.Eval(e.Item.DataItem, "ID") != 1)
{
e.Item.Attributes.Add(
"onmouseover", "this.style.textDecoration = 'underline';this.style.cursor='hand';this.style.color='#0096BD';");
e.Item.Attributes.Add(
"onmouseout", "this.style.textDecoration = 'none';this.style.cursor='pointer';this.style.color='#000';");
e.Item.CssClass =
"Blue1";
FontInfo fontinfo = e.Item.Font;
fontinfo.Name =
"Verdana";
fontinfo.Size = 8;
e.Item.Width = 166;
}
else
{
e.Item.CssClass =
"Blue";
FontInfo fontinfo = e.Item.Font;
fontinfo.Name =
"Verdana";
fontinfo.Bold =
true;
e.Item.ExpandedCssClass =
"BlueOtherStates";
e.Item.FocusedCssClass =
"BlueOtherStates";
}
}
}
catch (Exception ex)
{
Log.Error(
"Failed to applying styles for item " + e.Item.Text, ex);
throw;
}
}