Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I am using google chart , for that i have webmethod which is present on parent page , and i.e static . I want to access user controls dropdowns value or hiddent field value from my webmethod . how can that be possible ??

This is my webmethod present on my parent page .
C#
[WebMethod]
public static List<object> GetChartData()
{
    ActusLibrary.GoogleChartReportFilters obj = new ActusLibrary.GoogleChartReportFilters();
    List<object> lstData = ActusLibrary.Objectives.GetChartData(obj,ApConfig.CurrentCompany.CompId);
    return lstData;
}

this is my user cobntreols method which is again static and gets called from my webmethid .
C#
public static List<object> GetChartData(GoogleChartReportFilters objFilter,int? companyId)
{
    string query = "usp_GetObjectivesDetailsForGoogleChart";
    string constr = ApConfig.ConString;
    List<object> chartData = new List<object>();
    chartData.Add(new object[]
    {
        "Objective_Status", "Percentage"
    });
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand(query))
        {
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@CompanyId", companyId);
            cmd.Parameters.AddWithValue("@DateFilter", objFilter.DateFilter);
            cmd.Parameters.AddWithValue("@MoreThanLessThanStatus", objFilter.MoreThanLessThanStatus);
            cmd.Parameters.AddWithValue("@MoreThanLessThanValue", objFilter.MoreThanLessThanValue);
            cmd.Parameters.AddWithValue("@ObjectivesStatus", objFilter.ObjectivesStatus);
            cmd.Parameters.AddWithValue("@ObjectivePeriod", objFilter.ObjectivePeriod);

            cmd.Connection = con;
            con.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    chartData.Add(new object[]
                    {
                        sdr["Objective_Status"].ToString(), sdr["Percentage"]
                    });
                }
            }
            con.Close();
            return chartData;
        }
    }
}

I want to access user controls hidden field data from my webmethod and pass it to my child controls method ..
Posted
Updated 5-May-15 2:49am
v2
Comments
F-ES Sitecore 5-May-15 9:00am    
web methods can't access user controls. If your webmethod needs data from the page then it needs to accept that data via method parameters and your calling js needs to read the data from the page and pass it as parameters when it called the method. If you google calling a webmethod with parameters from javascript you'll find examples of this. Needless to say the reverse is also true, your webmethod can't update controls on the page either, the webmethod will need to return the data (serialised as json) and the calling js will need to update the DOM to reflect the data passed back from the webmethod...ie adding\removing markers etc.

F-ES Sitecore is correct. WebMethod should get some parameter and return you some value. Take that value and do any operation you want through JavaScript/jQuery.
 
Share this answer
 
Comments
Torakami 6-May-15 2:37am    
thanks for you suggestion . i have just added data parameter via ajax call and received that from webmethod
Awesome. :) Most welcome buddy. :)
XML
filterRecords = [];

        filterRecords[0] = $("#<%=drpDateFilter.ClientID%>").val();
        filterRecords[1] = $("#<%=drpMoreThanLessThanStatus.ClientID%>").val();
        filterRecords[2] = $("#<%=drpMoreThanLessThanValue.ClientID%>").val();
        filterRecords[3] = $("#<%=drpObjectivesStatus.ClientID%>").val();
        filterRecords[4] = $("#<%=drpObjectivePeriod.ClientID%>").val();


        $.ajax({
            type: "POST",
            url: "Home.aspx/GetChartData",
            data: JSON.stringify({ paramName: filterRecords }),



and on Webmethod :-

XML
[WebMethod]
      public static List<object> GetChartData(string[] paramName)
      {



}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900