in

Stuart Manning

Belfast Web Development | C# | ASP.NET | Ajax | LINQ | JQuery | CSS | Flex

ASP.NET

Accessing a Hyperlink (or other server control) inside a usercontrol - Custom Server Control Example for JavaScript reference

Need to shorten a server control ClientId to be accessible from JavaScript. This example creates a custom hyperlink control with shorted ClientID sans control id.

using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


/// <summary>
/// Summary description for hyperlink
/// </summary>
/// 
namespace Gasta.CustomControl
{


    public class href : HyperLink
    {


        public override string ClientID
        {
            get
            {
                return this.ID;
            }
        }
    }
}



 

Web.config <- add

<pages>
<add tagPrefix="custom" namespace="My.CustomControl"></add>
</pages>


ASPX
<custom:href runat="server" id="li_nav_web" href="/Default.aspx" mce_href="/Default.aspx">Web</custom:href></h1>

Reference

http://msdn.microsoft.com/en-us/library/yhzc935f.aspx
http://blog.danbartels.com/archive/2005/11/11/1110.aspx

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add

About Stuart Manning

ASP.NET 3.5 C#, CSS, Javascript and loving it