Sometimes you need to call a method written in codebehind(.aspx.cs) from .aspx page.
Here is a simple example:
In your aspx page
<asp:Label ID="lbllable" runat="server" text='<%# GetCustomerID() %>' />
In your codebehind(.aspx.cs) page
- private string _CustomerID = "8888";
- protected void Page_Load(object sender, EventArgs e)
- {
- lbllable.DataBind();
- }
- public string GetCustomerID
- {
- get { return this._CustomerID; }
- }
When you are using in gridview or any other data bound control then
in your aspx page
<%# GetEmployee(Eval("EmpId"))%>
in your codebehind
public object GetEmployee(object EmpId)
{
EmpId = 1234;
return EmpId;
}
0 comments:
Post a Comment