Reputation: 22956
I have something like this in Site.Master in an asp.net mvc3 (not razor) project:
<telerik:RadRibbonBar ID="RadRibbonBar1" runat="server">
The code behind is defined as such:
<%@ Master Language="C#" Inherits="myproject.Site_Master" CodeFile="Site.Master.cs" %>
So Site.Master.cs is:
using System.Web.Mvc;
using System;
namespace myproject
{
public partial class Site_Master : ViewMasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
How can I access radribbonbar1 from Page_loaded (which does get called once the page loads).
I was under the impression by giving it an ID it would be autogenerated to be accessible via C# code but that isn't happening (there is no variable radribbonbar1 available to Site_master).
Any ideas for how to make this work?
Upvotes: 1
Views: 138
Reputation: 1959
Server controls will not work properly because they require event handling, which you do not have in ASP.NET MVC. See the jQuery ribbon plugin
Upvotes: 2
Reputation: 26307
Didn't test this with your example but something like this might work
public static Control FindControlRecursive(Control root, string id)
{
return root.ID == id ? root : (from Control c in root.Controls select FindControlRecursive(c, id)).FirstOrDefault(t => t != null);
}
And, in your page_load
RadRibbonBar radRibbonBar1 = (RadRibbonBar)FindControlRecursive(Page, "RadRibbonBar1");
Upvotes: 1