Loading ...

Call C# code within ASPX page | CodeAsp.Net

Call C# code within ASPX page

 /5
0 (0votes)

How to call C# code within ASPX page

Many times we might need to call the C# or VB.NET code from within the ASPX page instead of using a code-behind file. Here is a quick code snippet to do the same:

 

<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
    MyLabelControl.Text = "time is " + DateTime.Now.ToString();
}
//now a button click event handler
void Button1_Click(Object sender, EventArgs e)
{
    MyLabelControl.Text = "Clicked at " + DateTime.Now.ToString();
}
</script>

 

Comments (no comments yet)

Top Posts