Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi every one
i add this
<script type="text/javascript">
function g(par)
{
    if (par=='d')
    {
        alert('d');
        <% dd();%>; // call c# method  
    } 
}
</script>

to aps.net
whay in form load this function must raise

why?
Posted
Updated 27-Apr-11 9:07am
v2
Comments
Monjurul Habib 27-Apr-11 15:09pm    
what you mean by "whay in form load this function must raise" ? and <% dd();%>; // call c# method
please share your exact code.
Mostafa Elsadany 27-Apr-11 15:24pm    
ok the idea
i want call c# method from javascript
so
i declare function javascript
and in this function i put
<% dd();%>; // call c# method
dd(); is method c#
ok
when i run project this dd();
is run without call he g(par)
so why

i think that you need to use Page.GetPostBackEventReference() to post your form so you can call methods on Server-Side.

See this [^]

good luck;
 
Share this answer
 
Comments
Manfred Rudolf Bihy 28-Apr-11 13:46pm    
Sounds reasonable! 5+
Ali Al Omairi(Abu AlHassan) 28-Apr-11 16:59pm    
Thank you,sir;
You have some confusion about what is evaluated when and where. The code snippet you showed us is from your ASP.net aspx page. This page in conjunction with the code behind file is run on the server side. The output is being rendered to HTML including the javascript you have in your aspx page. The tags you included inside the javascript block are also only evaluated on the server side. So all you achieved is that the method dd() is being called at the execution time on the server. If you want to call a server side method while the javascript is being exeuted on the client you'd have to use ASP.NET postback or AJAX.

Regards,

-MRB
 
Share this answer
 
Comments
walterhevedeich 27-Apr-11 21:38pm    
I agree. My 5. :)
Mostafa Elsadany 28-Apr-11 13:23pm    
thanks fro help
Manfred Rudolf Bihy 28-Apr-11 13:45pm    
I'm glad if it helped you. Please also consider Walter's approach of using jQuery to do the heavy lifting in conjunction with Page Methods.

Happy coding!
Mostafa Elsadany 28-Apr-11 15:24pm    
do you want know my problem
if you have background in use devexpress tools in asp.net
Manfred Rudolf Bihy 28-Apr-11 15:33pm    
I'm sorry to say that I do not have any knowledge of devexpress tools. My knowledge is more general javascript, Ajax and javascript frameworks like jQuery and PrototypeJS.
I agree with the 1st solution. You might want to use AJAX to accomplish this task. Read more about PageMethods. Here are some links to get you started.
Using PageMethods and JSON in ASP.NET AJAX[^]
Calling Server Side Code from Client Side using Ajax[^]

Alternatively, you can also use JQuery to do this. See below.
Using jQuery to directly call ASP.NET AJAX page methods[^]
 
Share this answer
 
v2
Comments
Mostafa Elsadany 28-Apr-11 13:23pm    
thanks fro help
Manfred Rudolf Bihy 28-Apr-11 13:46pm    
Great links! 5+

I must admit I love jQuery :)
Ali Al Omairi(Abu AlHassan) 28-Apr-11 17:08pm    
i agree its realy cool.

you know what the cp is a great site every day i learn new things from this site.
walterhevedeich 29-Apr-11 4:42am    
thanks.
Ali Al Omairi(Abu AlHassan) 28-Apr-11 17:12pm    
hundred of roses man, great links;

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