how to call method from code-behind

风格不统一 提交于 2019-12-24 10:47:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!