tags:

views:

46

answers:

3

I have a div like this :

<div id="div1" style="width: 100%; height: 30px; background-color: Blue" onclick="function1()"></div> 

from this function1() which is a javascript function I want to call a function which written in c# code behind so that i can access the controls of the page and do my manipulation whatever i want to do.

A: 

You cannot call C# directly from javascript on your website. You need to use AJAX for this. http://en.wikipedia.org/wiki/Ajax_%28programming%29

joni
A: 

If you are using mvc expose your method as an action on a controller and call with ajax.

Or use pagemethods

Expose yourmethod as a 'webmethod', eneable pagemthods in your Scriptmanager

and you can call by in your js by:

PageMethods.YourMethodName(yourParam,aCallBackFunction)

Then create a callback function in js to do something with your result.

John Nolan
A: 

Dear all, I found this simple answer in ur javascript function u need to do a postback to ur page with the argument name like this:

function function1() {
   __doPostBack('', 'MyButtonClick');
}

then in .cs page u need to catch this in page_load event like this :

if (Page.Request.Params["__EVENTARGUMENT"] == "MyButtonClick")
{
   function1();//this will take u to ur .cs function 
}
NayeemKhan