问题
How to call method from code-behind.I use asp.net n c#.I'm not familiar in .net environment.This is my example c# in code-behind:
public void HandleAction()
{
//HandleAction content
}
public void WriteTable()
{
//WriteTable content
}
I want to call it in markup page. I have use Response.Write to write the data in webpage.
回答1:
You can call c# function in markup by using server tags
<%= function() %>
Please find more detail here :-http://weblogs.asp.net/ahmedmoosa/archive/2010/10/06/embedded-code-and-inline-server-tags.aspx
回答2:
I have found the answer..It should be call like this in markup <%WriteTable();%>
.
回答3:
you have to use RegisterClientScriptBlock. This may help you.
public void HandleAction()
{
//HandleAction content
string jScript;
jScript="<script>alert ('Javascript block of code executed')</script>";
Page.RegisterClientScriptBlock("keyClientBlock",jScript);
}
By using the above code you can register a client side function also.
回答4:
Methodname is the name of your c# method..
You can call it the page load or button click or any event that causes a postback..
<%=MethodName()%>
来源:https://stackoverflow.com/questions/18739062/how-to-call-method-from-code-behind