Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi everyone
how i can
call void c#
the void name is test
from Javascript

or from client side events
thanks for any help
Posted

http://www.dotnetcurry.com/ShowArticle.aspx?ID=109[^]

I hope the above information will be helpful. If you have more concerns, please let me know.
 
Share this answer
 
Comments
ankitjoshi24 6-Apr-11 15:58pm    
5 to you....

the article was good
Monjurul Habib 6-Apr-11 16:19pm    
thank you.
I don't thing it is possible to directly do the stuff you are trying. Server-side function live on server-side and the client-side function love on the client. The only way to get any server-side code to run is to submit the form. ASP.NET unrolls the HTTP headers, unpacks the hidden ViewState variable, re-instantiates objects, and then decides what events to raise based on all of the above.

What you can do is have your Javascript function set a hidden form variable, then do a form.submit().

Then in your Page_Load handler on the server, use the Request object to check for the presence and/or value of this variable, and call the appropriate server-side method.

Hope this helps. I am not an expert but I found this way while searching for your question. If anyone knows any other way please let me know too.

--
AJ
 
Share this answer
 
Sounds like you want to know how to talk to server from Javascript.
There are few ways to interact with server side through client side(Javascript):
1. XMLHttpRequest[^]
2. Callback[^]
3. WebService call[^]
4. PageMethod[^]
 
Share this answer
 
Comments
Albin Abel 6-Apr-11 16:28pm    
Good choices. My 5
Sandeep Mewara 7-Apr-11 0:58am    
Thanks Albin.
You can't directly call a code-behind method from javascript because that would be crossing the client side/server side boundary. I would think a workaround would be to set a hidden form variable to inidcate what method you want to call (in the event that there are more than one), and then call form.submit(). At that point, you can probably handle the Request object in the Page_Load method the page that you submitted to, and call the desired method.
 
Share this answer
 
thanks for every one
i have problem when call method c# from javascript in asp.net


function calle()
{

<![CDATA[<%SetData();%>]]>;

}



public void SetData()
{
int x;
TextBox1.Text = ASPxGridView1.GetSelectedFieldValues("id")[0].ToString();

}
so i add calle()
to clinet side events
ok it's working but just one
to work again must press enter in textbox to work again
so gso what a problem a
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900