Vani
Vani

Reputation: 1353

How to call server-side function using html button?

I know this is a weird question but I was pushed to such a situation. I have to refresh a ESRI client side map and call server-function at the same time. I am using c#/asp.net/javascript.

I think we can call web service methods, but it is possible to call the server-side function of the same page.

EDITED Thanks for the reply. But I am dealing with a different situation. In my server -side function I have to access the "div" and have to add images whose URL are coming from database.Since the webmethods are static, I can't access the "div" element. Does it make any sense or am I doing something wrong

ANSWER

txt.Attributes.Add("onclick", "refreshMap(); return false;");

I missed return false before and that's causing postback every time.

Thanks,

Upvotes: 2

Views: 3380

Answers (2)

Igbanam
Igbanam

Reputation: 6082

I am new to this but I think Mike's approach is ideal. If you find this slowing down your site, try implementing it using Web Workers.

Upvotes: 0

khr055
khr055

Reputation: 29042

You could do this by having the onclick event call a function which makes an AJAX post to a method in your code-behind. This will work with WebMethods.

Upvotes: 1

Related Questions