javascript - call C# function from HTML link -


i'm developing asp.net c# website. on website gridview data in it, , should able export data (excel, whatever).

for export use code on website.

when clicks export link popup fire this:

enter image description here

the popup made avgrund , "buttons" html links.

$(function () {         $('#exportlaces').avgrund({             height: 80,             width: 380,             holderclass: 'container',             showclose: true,             showclosetext: 'x',             closebyescape: true,             onblurcontainer: '#main-wrapper',             template: '<div id="exportpopuptop"></div>' +             '<div id="exportpopup">' +             '<ul>' +             '<li><a href="#">excel</a></li>' +             '<li><a href="#">html</a></li>' +             '</ul>' +             '</div>'      }); }); 

i need fire c# code html links export. how?

i tried this:

<a runat="server" onserverclick="myfunction_click">excel</a> 

but doesn't work since i'm outside of form tag. , 1 form tag allowed runat="server".

i tried add asp.net buttons popup, didn't work either.

is there way fire javascript function fire c# ?

thanks help.

edit

the code looks this

$(function () {     $('#exportlaces').avgrund({         height: 80,         width: 380,         holderclass: 'container',         showclose: true,         showclosetext: 'x',         closebyescape: true,         onblurcontainer: '#main-wrapper',         template: '<div id="exportpopuptop"></div>' +         '<div id="exportpopup">' +         '<asp:linkbutton id="linkbutton1" runat="server" onclick="linkbutton1_click"> excel</asp:linkbutton>' +         '</div>'     }).appendto("#form1"); }); 

and c# code behind this:

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols;  namespace lace {   public partial class default : system.web.ui.page   {      protected void linkbutton1_click(object sender, eventargs e)     {         // server side code goes here...     }    } } 

and following error message:

compiler error message: cs1061: 'asp.default_aspx' not contain definition 'linkbutton1_click' , no extension method 'linkbutton1_click' accepting first argument of type 'asp.default_aspx' found (are missing using directive or assembly reference?)

i suggest call javascript function on html button click , in javascript function , can call server side function using asp.net ajax scriptmanager.

the first thing need add asp.net ajax scriptmanager page , set itsenablepagemethods property true shown below:

<asp:scriptmanager id="scriptmanager1" runat="server" enablepagemethods="true"> </asp:scriptmanager> 

now can call page method (c#) methods below javascript function :

pagemethods.getcurrenttime(document.getelementbyid("<%=txtusername.clientid%>").value,      onsuccess); 

where server side method follows:

[system.web.services.webmethod] public static string getcurrenttime(string name) { return "hello " + name + environment.newline + "the current time is: "     + datetime.now.tostring(); } 

you can call javascript function html control.

for detail , implementation can refer link.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -