开发者

How to Call a C# Function from a Button?

In my application I made some reports with the crystal reports and I used buttons to show my reports (PDF). I want the reports to be open in a new window, not in the same window as the application. I know about the hyperlink's target but how can I call a C# 开发者_StackOverflow中文版function in the hyperlink's property?


you could try something like...

  protected void Button1_Click(object sender, EventArgs e)
{
    //your code.....
    //then this will open your URL in new window
    Response.Write("<script>window.open('URL/pageName');</script>");
}


Use

__doPostBack 

and check for event target and event argument and call the C# function.

See

Understanding the JavaScript __doPostBack Function


Its not that you have to call c# function in Hyperlink property. that cannot be done.

For eg.

If your ReprotMain.aspx is the first page with the button "Click to view"

When you click the button it should show the report in DetailReport.aspx

Then you have to call Write or Call the same method to generate the report in both the pages. To prevent the repitation of the code. You can use a Common class to generate report and return to the page. so that is easy to call it. in any page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜