Solved

Access a server control[ASPX] from a static method

Posted on 2011-09-29
4
302 Views
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.
0
Comment
Question by:dev_intagleo
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
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
0
 

Author Comment

by:dev_intagleo
ID: 36890085
my ajax call
function UpdateChart(year) {
                $.ajax({
                    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.clearAll();
                shareGrid.load('Handlers/Reports/ShareHandler.ashx?yr=' + year);

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

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

                UpdateChart(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.clearAll();
                shareGrid.load('Handlers/Reports/ShareHandler.ashx?yr=' + year);
things??

0
 
LVL 9

Expert Comment

by:yeelokhk
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;
trigger.click();

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

0
 
LVL 9

Expert Comment

by:richard_hughes
ID: 36890950
Hello dev_intagleo

It sounds like you need to handle the AJAX response.

Try the attached code.

Thanks,

Richard
function UpdateChart(year) {
                $.ajax({
                    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
						change_Year(data.year);
					}
                });
            }

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now