Cannot Set Text OfficeButton in Runtime

Apr 11, 2011 at 8:15 AM

Hi,

I wantto set OfficeButton's Text in runtime. First I add OfficeButton on aspx page and then set Officebutton's Text. When I run application,I can not see any text on button.

Please help..

 

<OfficeWebUI:OfficeButton ID="btnSearch" runat="server" OnClick ="btnSearch_Click"></OfficeWebUI:OfficeButton > 

protected override void OnInit(EventArgs e) {

btnSearch.Text="Sample Text";

base

.OnInit(e);

}



Apr 11, 2011 at 9:13 AM

Hi Mehmet,

I assume you are using a master page, if so have you tried putting a reference into the aspx page to reference that master?  Let me know how you get on... (its in vb but i think you get the idea...)

<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="myExample.aspx.vb" Inherits="myExample" %>
<%@ MasterType VirtualPath="~/Site.master" %>
 
Once you have done that you can access the toolbar from the page you are on in the init event...
  

Dim

 

btnSearch As OfficeWebUI.Ribbon.LargeItem = DirectCast(Master.MainRibbon.getGroupZone("myZone").FindControl("btnSearch"), OfficeWebUI.Ribbon.LargeItem

)

btnSearch.Text =

"Sample Text"

Apr 11, 2011 at 11:36 AM

Hi kengliddon,

I use Master Page. I want to access <OfficeWebUI:OfficeButton> like <ASP:Button> .How can I do? 
I putted a referance and button into the aspx page. Code is above..
Thanks..

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind

="DocSearch.aspx.cs"
 
 

 

MasterPageFile="~/MasterPages/Main.master" Inherits="Mycroft.WebClient.DocSearch" %>

<%@ MasterType VirtualPath="~/MasterPages/Main.Master" %>

 

<OfficeWebUI:OfficeButton ID="btnSearch" runat="server" OnClick ="btnSearch_Click"></OfficeWebUI:OfficeButton > 





protected override void OnPreRender(EventArgs

e)
 

{  

 

if (!IsPostBack)

 

}

 

{

btnSearch.Text =Dictionary

.SEARCH;
 

base.OnPreRender(e);

}

Apr 12, 2011 at 8:12 AM

Hi Mehmet,

In order to access the search button you will need to create public properties to be able to get to them.

In your Main.master add the following:

public partial class Main : System.Web.UI.MasterPage
{
    //first expose the ribbon control to the pages...
    public OfficeWebUI.OfficeRibbon MasterRibbon
    {
        get { return this.OfficeRibbon1; }
        set { this.OfficeRibbon1 = value; }
    }

    public OfficeWebUI.OfficeWorkspace MasterWorkSpace
    {
        get { return this.Workspace1; }
        set { this.Workspace1 = value; }
    }

    public OfficeWebUI.Manager MasterManager
    {
        get { return this.Manager1; }
        set { this.Manager1 = value; }
    }
        
}

DocSearch.aspx should look something like:

<%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeFile="DocSearch.aspx.cs" Inherits="DocSearch" %>
<%@ MasterType VirtualPath="~/Main.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

</asp:Content>

And Finally the code behind for doc search is:

public partial class DocSearch : System.Web.UI.Page
{
    
    protected void Page_Init(object sender, System.EventArgs e)
    {
         (Master as Main).MasterRibbon.getRibbonItem<OfficeWebUI.Ribbon.LargeItem>("btnSearch").Text = "Hello Ken";
    }

}

Or the same thing in VB.Net for reference:

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        Master.MasterRibbon.getRibbonItem(Of OfficeWebUI.Ribbon.LargeItem)("btnSearch").Text = "Hello Ken"

    End Sub

End Class

Let me know how you get on.

Ken

May 5, 2011 at 7:44 AM

Thanks.. That worked