2

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,

2
  • 1
    javascript cant affect the server, but javascript can send request to the server which forces the server at client side to update something. this is ajax Commented Feb 2, 2011 at 0:44
  • @fehergeri 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. Commented Feb 2, 2011 at 18:29

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

@Mike,Thanks for the reply.But in the webmethods i cant update the controls rite? .I mean here i have to add images to the div in the server function.
You could. If you wanted, you could put runat="server" on the div that you wanted to add images to, then in the code behind, you can do: divID.InnerHtml = "<add markup for images here>". I admit it's, not the cleanest way of doing it. Does that help?
I am already doing that in my button_Click method .But when i changed to webmethod with static in order to get called by my AJAX call, all the server elements giving "An object reference is required for the non-static field, method, or property 'Default3.frame' " error.here frame is my "div" with runat="server" tag.
Ok, I see what you mean, my bad. >.< Mostly, I use webMethods in web services. So here's another thing you can do: return the string that you normally would have put in the InnerHtml from your static webMethod and use the callback function to set the html in the divs innerHTML property client-side.
Mike,you know what, i am the most stupid person . txt.Attributes.Add("onclick", "refreshMap(); return false;"); did the work. Since i am giving the return false in my script call,it postbacks everytime and the map is not refreshing. I appreciate ur response and thanks a lot.
|
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.