Skip to content Skip to sidebar Skip to footer

Disable Hyperlink Of Master Page From Content Page

<%@ Master Language='C#' AutoEventWireup='true' CodeBehind='AssociateMaster.master.cs' Inherits='EQ.AssociateMaster' %><%@ Register Assembly='AjaxControlToolkit' Namespac

Solution 1:

You can use jQuery to do that

//disable menu
$("#menu a").each(function(){
   $(this).attr("disabled","disabled");
});

You could similarly add a css class to your logout link and disable that too.

Solution 2:

Sorry didn't read your reply about doing it client side... but for server side:


You have to put a reference to the MasterPage in your page/user control markup.

<%@ Reference VirtualPath="..." %>

Then in the code-behind, you just cast the Page.MasterPage to your MasterPage and access its properties.

MyMasterPagemyMasterPage= (MyMasterPage)Page.Master;

Then you can:

HyperLinkmyLink= (HyperLink)MyMasterPage.FindControl("nameOfLink");
myLink .Visible = false;

Something along those lines, based on what I've seen before, C# is a bit rusty but the principal is there.

Solution 3:

For client side (using JS)

You can use JQuery:

$('a').bind("click.myDisable", function() { returnfalse; });

That will disable the click event for all hyperlinks.

Call the JQuery using these functions

publicboolrunJQueryCode(string message)

{ ScriptManager requestSM = ScriptManager.GetCurrent(Page); if (requestSM != null && requestSM.IsInAsyncPostBack) { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), Guid.NewGuid().ToString(), getjQueryCode(message), true); } else { Page.ClientScript.RegisterClientScriptBlock(typeof(Page), Guid.NewGuid().ToString(), getjQueryCode(message), true); }

returntrue;

}

private string getjQueryCode(string jsCodetoRun) { StringBuilder sb = new StringBuilder(); sb.AppendLine("$(document).ready(function() {"); sb.AppendLine(jsCodetoRun); sb.AppendLine(" });");

return sb.ToString();

}

So: runJQueryCode("$('a').bind('click.myDisable', function() { return false; });");

Post a Comment for "Disable Hyperlink Of Master Page From Content Page"