Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
How can I call a non static method from javascript?

I am using pagemethod.methodName();
It works fine when I use:
[WebMethod]
Public Static void methodName()
{
//Nothing
}

I want to call a non static method from javascript.
Is there any way to call a non static method? Please help.


Thanks in advance.
Posted
Updated 28-Apr-11 1:21am
v2
Comments
VC.J 10-Oct-14 1:03am    
not possible as far as I know I think by non static method u want to access the control ?

u can use Ajax dll for that

see this link

http://msdn.microsoft.com/en-us/library/aa479042.aspx[^]
 
Share this answer
 
Hello,

As far as I know, this is not possible.
From the logical side, this also would not make any sense, because for a non-static method (a instance method) you would need first an instance of any object, but the Ajax request just executes a method and does not instantiate a object.

Perhaps you will find a solution in remoting tools like WebOrb[^] for example. In Weborb, a instance will be created if the function you call is a instance-method.

Anyway, why you would need a static method to be executed? You would not get a correct page context (or any other context) in a ajax request. Is there a specific reason you try to do this?

Hope this helps.


Best regards and have a nice day,
Stops

---------
Check out my website http://dotnetcorner.ch/ and my blog http://blog.dotnetcorner.ch/
 
Share this answer
 
no that's not possible, you need to use static methods and then make your own objects there , so basically you need to know object oriented in asp.net
 
Share this answer
 
Comments
Member 12062651 2-Mar-16 8:53am    
one aspx page having one tab container on that tab container 15 tabs are there,each tab panel having user control that's why my page load time very high how can i reduce page load time
note: user controls having button click events
far6ad 4-Jul-16 2:58am    
you can only load once on page_load like this :

if(!ispostback)
loadTabs();
The less worse solution I can offer is the button.click
Unfortunately the button have to be visible and creates another problem. if you click the button itself, it fires again the code.

BUT it starts the code in none static way.

Some sample code :

JavaScript
$('#Button1').click();


ASP.NET
<asp:button id="Button1" runat="server" clientidmode="Static" text="Button" onclick="Button1_Click" />


Until I have a better solution this is my way to work.
 
Share this answer
 
v2

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