[英]how to call method from code-behind
如何從代碼隱藏中調用方法。我使用asp.net nc#。我對.net環境不熟悉,這是我在代碼隱藏中的示例c#:
public void HandleAction()
{
//HandleAction content
}
public void WriteTable()
{
//WriteTable content
}
我想在標記頁面中調用它。 我已經使用Response.Write在網頁中寫入數據。
您可以使用服務器標簽在標記中調用c#函數
<%= function() %>
請在此處找到更多詳細信息:-http: //weblogs.asp.net/ahmedmoosa/archive/2010/10/06/embedded-code-and-inline-server-tags.aspx
我找到了答案..應該在標記<%WriteTable();%>
這樣調用。
您必須使用RegisterClientScriptBlock。 這可能對您有幫助。
public void HandleAction()
{
//HandleAction content
string jScript;
jScript="<script>alert ('Javascript block of code executed')</script>";
Page.RegisterClientScriptBlock("keyClientBlock",jScript);
}
通過使用上面的代碼,您還可以注冊客戶端功能。
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()%>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.