Showing posts with label asp.net label. Show all posts
Showing posts with label asp.net label. Show all posts

Saturday, August 2, 2014

call codebehind method from asp.net controls like label to return a value

hi in this post i will show how to call a code-behind method from asp.net control. here i will be taking example with label.

Example :

Aspx page :

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   <asp:Label ID="Label1" runat="server"><%= GetName(" Singh") %></asp:Label>
    </div>
    </form>
</body>
</html>


Code behind :

  protected string GetName(string input)
    {
        return "Chandan" + HttpUtility.HtmlEncode(input);
    }
}


Output: