posted 4/26/2010 by Vivek Thakur
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>
void Button1_Click(Object sender, EventArgs e) { MyLabelControl.Text = "Clicked at " + DateTime.Now.ToString();}
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18