'Label server side click

I have a label control and and JavaScript function callme() as follows. When a click on Press label, it works.

<asp:Label ID="lblpress" runat="server" onclick="callme()" Text="Press"></asp:Label>

I want to click this label client side event, programatically from server side event. How can I do it?



Solution 1:[1]

you can use RegisterClientScriptBlock for doing this.

    String csName = "LabelClickScript";    
    ClientScriptManager cs = Page.ClientScript;   
    StringBuilder csText = new StringBuilder();
    csText.Append("<script type=\"text/javascript\"> function DoClick() {");
    csText.Append("alert('Text from client script.')

                    } 
                    DoClick();
                  </");
    csText.Append("script>");
    cs.RegisterClientScriptBlock(this.GetType(), csName, csText.ToString());

Solution 2:[2]

why dont you use proper controls like ,link button or Anchor in HTML

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Behnam Esmaili
Solution 2 LearningAsp