Set RadButton NavigateUrl from code behind

Posted by Community Admin on 04-Aug-2018 15:13

Set RadButton NavigateUrl from code behind

All Replies

Posted by Community Admin on 11-May-2013 00:00

I need to be able to grab the current page title on page load, adjust the url a bit and set the NavigateUrl property of a RadButton. For some reason I must be missing something because I can't seem to get it to work. If anyone can tell me what's wrong I would appreciate it. I have a feeling it's going to be one of those forehead slap moments. The RadButton declaration I'm using is:

<telerik:RadButton ID="RadButton1" runat="server" Width="162px" Height="32px" Text="MyLink" cssclass="mylink" hoveredcssclass="mylinkhovered" NavigateUrl="'<%# Eval(NavigateUrl) %>'">
                <Image EnableImageButton="true" />
</telerik:RadButton>

and the code behind I'm working with is:

        private string _navigateurl;
        public string NavigateUrl
       
            get
           
                return _navigateurl;
           
            set
           
                _navigateurl = value;
           
       
        protected void Page_Load(object sender, EventArgs e)
       
            string pagetitle = SiteMapBase.GetActualCurrentNode().Title;
            _navigateurl = "/my-link/" + pagetitle;
                            
       

Thanks in advance,

Scott

Posted by Community Admin on 11-May-2013 00:00

I don't even think I'm getting the page title. When I just try to write it out on the page with:

string pagetitle = SiteMapBase.GetActualCurrentNode().Title;
HttpContext.Current.Response.Write(pagetitle);

I get nothing?

Scott

Posted by Community Admin on 11-May-2013 00:00

Not sure what is going on with this particular masterpage, but I could not get the page_load to fire, and I also found that when adding the RadButton control to the page in sourceview, it wouldn't add the corresponding code needed in the designer.cs file, so it wouldn't recognize anything about the RadButton in code behind and is why I thought I needed to use properties and the "Eval" statement. 

I created a new masterpage and manually added the RadButton reference to the designer.cs file and was able to do what I needed. Response.Write works as well on this new page. Here is what I came up with. It's kind of a hack but it works.

string pageUrl = SiteMapBase.GetActualCurrentNode().Title;
string navigateUrl = "/different-pagegroup-menu/" + pageUrl;
RadButton1.NavigateUrl = navigateUrl;

Scott

Posted by Community Admin on 13-May-2013 00:00

Can you give a bit more details?  Is the button just ON the masterpage, or inside a Simpleview or UserControl?

(also, do you have a CSS\JS Embed widget on the masterpage anywhere?)

Posted by Community Admin on 13-May-2013 00:00

Hi Steve,

The button is on the masterpage and I do have ResourceLink tags referencing some .js/jQuery files, along with a couple link references to .css files. 

I got it to finally work by creating a new masterpage file, adding the ResourceLinks and .css file links and the code in the page_load. I don't know what the problem was with the original masterpage file's page_load not firing was but one thing I did notice was the RadButton1 declaration in the designer.cs file was missing. I closed the project and created a new one(normal asp.net web project), created a test page and dragged the RadButton from the toolbox onto the page, copied the RadButton1 declaration in it's designer.cs file. 

Then opened my Sitefinity project back up and pasted the declaration into my new masterpage's designer.cs file and my intellesense started working on the RadButton1 object. If you drag the RadButton from the VS toolbox onto the design view of the page everything works, but if you try to copy and paste a RadButton statement into source view of the page it doesn't want to add the declaration to the designer.cs file. So it seemed like I had two issues overall.

Have you ever seen issues with css/js files referenced in masterpages effect things like this before? 

Posted by Community Admin on 13-May-2013 00:00

Yes that's why I asked :)  But the problem was with the CssEmbed and Javascript Embed controls, not the resourcelinks (different controls)

The workaround was to just Cut the embed controls out of the master, save (designer.cs then updated itself) then just paste the control back where they were.

Incidentally (you prob know...but) you don't need to drag\drop anything in order for designer.cs to be updated, you just need to save the .master in VS.

This thread is closed