Tuesday, July 22, 2014
No Comments Yet!!!
Not Downloaded Yet!!!
C# Method from ASPX Page call C# Method
How can we call a C# Method from ASPX Page or Code Behind page
In some situation, we have the requirement to call a C# Method from the ASPX Page or Code Behind page
So to solve this, first we create a website by using Visual Studio(any edition).
Step 1: Open Visual Studio and create a new ASP.NET website
Step 2: Add a new webform by right click on the solution or from the file menu
Step 3: Add the following code to the aspx page(design mode). In this step we are adding a label control to the webpage or aspx page. Name the label control as "lbllable"
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Step 4: after that go to the Code Behind page and add the below codes. In the codes, we are creating a simple method which is returning the "CustomerID"
public partial class _Default : System.Web.UI.Page
private string _CustomerID = "ID101";
public string GetCustomerID()
protected void Page_Load(object sender, EventArgs e)
Step 5: Run the application, sure you will get the below screenshot result
Output will be like this....
So In this article we learn how we can call a C# Method from the ASPX Page or Code Behind page, stay tuned for much and more excited articles on asp.net.
Download Source Codes