Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Access a server control[ASPX] from a static method

Posted on 2011-09-29
Last Modified: 2012-05-12
I have a Chart control on an ASPX Page. On aspx page i have a dropdown of year
now i m using JQuery ajax call to send that change year to code behind file,
there i have a static method[due to ajax]
so i have to access my chart control there
Is there any way to do that, i am unable to access the chart control here due to static thing.

I want to redraw the chart based on the new value of year.
Question by:dev_intagleo
  • 2

Accepted Solution

yeelokhk earned 500 total points
ID: 36890040
How do you make your ajax call?

Try to use ASP.NET AJAX UpdatePanel to make the ajax call. It allows you to call a non-static code-behind function.

Take a look at: http://www.dotnetfunda.com/articles/article471-jquery-and-aspnet-ajax-updatepanel-.aspx

Author Comment

ID: 36890085
my ajax call
function UpdateChart(year) {
                    type: "POST",
                    url: "Reports.aspx/UpdateCharts",
                    data: '{year: "' + year + '" }',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json"
Actually problem with ASP.NET AJAX UpdatePanel is that
this is not the only call i want to make when year dropdown changes. i m using a third party control on client side. when year drop down changes it will do following
function change_Year(year) {
                var year = year.value;
                shareGrid.load('Handlers/Reports/ShareHandler.ashx?yr=' + year);

                salesGrid.load('Handlers/Reports/SalesHandler.ashx?yr=' + year);

                marketGrid.load('Handlers/Reports/MarketHandler.ashx?yr=' + year);

i also want to call the handlers as i m doing above and in the end call UpdateChart(year); which in turns call
jQuery ajax, so if i use MS AJAX update panel, how can i do the handlers call, do i have access to
                shareGrid.load('Handlers/Reports/ShareHandler.ashx?yr=' + year);


Expert Comment

ID: 36890144
With ASP.NET AJAX UpdatePanel, you can invoke the AJAX Postback manually by Javascript.

Firstly, you client-side control should be some jQuery control, right? not a asp.net control?
If so, then, you create a ASP.NET Button Control for the trigger of the UpdatePanel (temporary name it as btn_trigger). But this Button is only used for the triggering of the postback, so make sure you set the visibility to false to hidden it. (This Button must put in the UpdatePanel as well as your Chart)

Second, add a Button Click event handler to btn_trigger in code-behind to handler the changes.

Thrid, in your javascript. Invoke the Click event of btn_trigger by:
var  trigger = document.getElementById('" + btn_trigger.ClientID + @"');
trigger.value = year;

Open in new window

Last, in the click event handler of btn_trigger in your code-behind.
Use the following code to retrieve the year.
string year = btn_trigger.Text;

Open in new window


Expert Comment

ID: 36890950
Hello dev_intagleo

It sounds like you need to handle the AJAX response.

Try the attached code.


function UpdateChart(year) {
                    type: "POST",
                    url: "Reports.aspx/UpdateCharts",
                    data: '{year: "' + year + '" }',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
					success: function (data) {

						// change this to suit your JSON response format

Open in new window


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question