473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

call a function

145 100+
How do I call following function from a Text Link?
Like, I want to call the export function when user click on this link.
Click here to Export to Excel

I tried this but it's not working.
<a href="Export2Excel()" id="link">Export to Excel</a><br />


Expand|Select|Wrap|Line Numbers
  1.     protected void Export2Excel()
  2.     {
  3.         Response.Clear();
  4.         Response.Buffer = true;
  5.  
  6.         Response.AddHeader("content-disposition", "attachment;filename=EmployeeList.xls");
  7.         Response.Charset = "";
  8.         Response.ContentType = "application/vnd.ms-excel";
  9.         StringWriter sw = new StringWriter();
  10.         HtmlTextWriter hw = new HtmlTextWriter(sw);
  11.  
  12.         GridView2.AllowPaging = false;
  13.         GridView2.DataBind();
  14.  
  15.         for (int i = 0; i < GridView2.Rows.Count; i++)
  16.         {
  17.             GridViewRow gvRow = GridView2.Rows[i];
  18.         }
  19.         GridView2.RenderControl(hw);
  20.         Response.Output.Write(sw.ToString());
  21.         Response.Flush();
  22.         Response.End();
  23.     }
  24.  
Apr 14 '09 #1
3 1569
maliksleo
115 100+
i think you should use link botton of asp instead of <a/> and in its onclick event call your function.
or
use onclick event in your <a/> tag with runat server = true i think u can do this from here but i m not sure but in case of linkbutton i m sure you can call a function

maliksleo
Apr 15 '09 #2
Frinavale
9,735 Expert Mod 8TB
Instead of using an HTML hyperlink, use a LinkButton and configure it so that it calls that function during the OnClick event.

You could either add an event handler to the LinkButton in your C# code, or you could add set the OnClick property of the LinkButton in your ASP code to the function.

For Example (ASP method):
Expand|Select|Wrap|Line Numbers
  1. <asp:LinkButton id="exportToExcel" runat="server" OnClick="Export2Excel()" Text="Export to Excel></asp:LinkButton>
C# method:
Expand|Select|Wrap|Line Numbers
  1. exportToExcel.Click += new EventHandler(Export2Excel);

For this to work you have to change your Export2Excel method definition to:

Expand|Select|Wrap|Line Numbers
  1. protected void Export2Excel(object sender, EventArgs e)
Apr 15 '09 #3
dorandoran
145 100+
Thank you Frin for showing me in details. I truly appreciate it.

Again Thanks a LOOTTTTTTTTT
Apr 15 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.