|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Defining server-side Click event for Label web contol ?I am using a label on my webform, wherein i want that on clicking the user
must be directed to next page(just like hyperlink). I have added the onclick attribute to label contol as follows : Label1.attributes.add("onclick","") Now I want that whenever the user clicks the label a server side onlick event be fired, just as in case of buttons. How should i do that ? Pls Help. Any help is appreciated Thank You. Saket Mundra a label is historically a piece of text on a form. if you need clickability,
use a button and set its border appropriately -- Show quoteHide quoteRegards, Alvin Bruney - ASP.NET MVP [Shameless Author Plug] The Microsoft Office Web Components Black Book with .NET Now available @ www.lulu.com/owc "Saket Mundra" <SaketMun***@discussions.microsoft.com> wrote in message news:F5602604-00D0-4B48-804A-3AC00D3AF154@microsoft.com... >I am using a label on my webform, wherein i want that on clicking the user > must be directed to next page(just like hyperlink). > > I have added the onclick attribute to label contol as follows : > Label1.attributes.add("onclick","") > > Now I want that whenever the user clicks the label a server side onlick > event be fired, just as in case of buttons. How should i do that ? > > Pls Help. Any help is appreciated > Thank You. > > Saket Mundra Maybe you could have it easier by using a LinkButton, which's style you set
to be non-underlined (if having link-like style isn't an option). And sure, you could develop a custom control for this task also if you insist that it should be a Label, here's an example: using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ClassLibrary2 { /// <summary> /// Summary description for ClickableLabel. /// </summary> public class ClickableLabel : Label,IPostBackEventHandler { #region "Click event" private static readonly object EventClick=new object(); public event EventHandler Click { add { Events.AddHandler(EventClick,value); } remove { Events.RemoveHandler(EventClick,value); } } protected void OnClick(EventArgs e) { EventHandler h=Events[EventClick] as EventHandler; if(h != null) h(this,e); } #endregion //When postback is caused by this control, raise the event void IPostBackEventHandler.RaisePostBackEvent(string eventArgument) { if(eventArgument =="lbl") OnClick(EventArgs.Empty); } //Add onclick attribute to cause a postback when Label is clicked protected override void AddAttributesToRender(HtmlTextWriter writer) { base.AddAttributesToRender (writer); writer.AddAttribute(HtmlTextWriterAttribute.Onclick,Page.GetPostBackEventReference(this,"lbl")); } } } -- Show quoteHide quoteTeemu Keiski ASP.NET MVP, AspInsider Finland, EU .. "Saket Mundra" <SaketMun***@discussions.microsoft.com> wrote in message news:F5602604-00D0-4B48-804A-3AC00D3AF154@microsoft.com... >I am using a label on my webform, wherein i want that on clicking the user > must be directed to next page(just like hyperlink). > > I have added the onclick attribute to label contol as follows : > Label1.attributes.add("onclick","") > > Now I want that whenever the user clicks the label a server side onlick > event be fired, just as in case of buttons. How should i do that ? > > Pls Help. Any help is appreciated > Thank You. > > Saket Mundra
Customizing ASP.NEt Hyperlink Control
IE Web Controls - discontinued ??? Need Click Event to Fire from TextBox custom validator and button events custom validator and button events Urgent! GridView and templated controls binding---------Plz help Control Template How do I post hidden variables to another form from a popup? Creating a Tab in web form Sorting problem in Data grid control |
|||||||||||||||||||||||