Solved

Access a server control[ASPX] from a static method

Posted on 2011-09-29
4
312 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
[X]
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
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
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…

630 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