Calling non-static method from static webmethod
-
[System.Web.Services.WebMethod] public static DataSet GetContactName() { DataSet ds = new DataSet(); XmlDocument doc = new XmlDocument(); ds.ReadXml(System.Web.HttpContext.Current.Server.MapPath("App_Data/Group.xml")); LoadData(ds); ????? } I need to bind this ds to a repeater control. public void LoadData(DataSet ds) { DataSet ds = GetContactName(); repeaterGroup.DataSource = ds; repeaterGroup.DataBind(); } My question is, how to call LoadData from above webmethod. LoadData() method is not recognized from the webmethod.
------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates
-
[System.Web.Services.WebMethod] public static DataSet GetContactName() { DataSet ds = new DataSet(); XmlDocument doc = new XmlDocument(); ds.ReadXml(System.Web.HttpContext.Current.Server.MapPath("App_Data/Group.xml")); LoadData(ds); ????? } I need to bind this ds to a repeater control. public void LoadData(DataSet ds) { DataSet ds = GetContactName(); repeaterGroup.DataSource = ds; repeaterGroup.DataBind(); } My question is, how to call LoadData from above webmethod. LoadData() method is not recognized from the webmethod.
------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates
How can a web-service method binds data? If
LoadData()
method is in your web page and you are trying to call it from web-service, then whatever you are doing is pointless. Do more reading on web-services and how they work before you work on them.Navaneeth How to use google | Ask smart questions
-
How can a web-service method binds data? If
LoadData()
method is in your web page and you are trying to call it from web-service, then whatever you are doing is pointless. Do more reading on web-services and how they work before you work on them.Navaneeth How to use google | Ask smart questions
Everything has a necessity and I wanted to clearly communicate that am not a beginner. Please ask why this is needed if you are interested to help or opt to stay out. There will be somebody else who will be willing to help. When I have posted a question on a forum, it clearly means I am looking for a solution. This is what am trying to achieve. Ajax control, collapsible panel extender(cpe) needs to expand a panel containing a repeater control and load data into repeater when the panel is expanded. I found that there is no server side click event but there is an expand-collapse javascript handler. To call server side code from AJAX, Pagemethods can be used. <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server"> </asp:ScriptManager> [System.Web.Services.WebMethod] public static DataSet GetContactName() { DataSet ds = new DataSet(); XmlDocument doc = new XmlDocument(); ds.ReadXml(System.Web.HttpContext.Current.Server.MapPath("App_Data/Group.xml")); LoadData(ds); } public void LoadData(DataSet ds) { DataSet ds = GetContactName(); repeaterGroup.DataSource = ds; repeaterGroup.DataBind(); } I am not able to access LoadData from GetContactName(). Any help on this would be greatly appreciated.
------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates
-
Everything has a necessity and I wanted to clearly communicate that am not a beginner. Please ask why this is needed if you are interested to help or opt to stay out. There will be somebody else who will be willing to help. When I have posted a question on a forum, it clearly means I am looking for a solution. This is what am trying to achieve. Ajax control, collapsible panel extender(cpe) needs to expand a panel containing a repeater control and load data into repeater when the panel is expanded. I found that there is no server side click event but there is an expand-collapse javascript handler. To call server side code from AJAX, Pagemethods can be used. <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server"> </asp:ScriptManager> [System.Web.Services.WebMethod] public static DataSet GetContactName() { DataSet ds = new DataSet(); XmlDocument doc = new XmlDocument(); ds.ReadXml(System.Web.HttpContext.Current.Server.MapPath("App_Data/Group.xml")); LoadData(ds); } public void LoadData(DataSet ds) { DataSet ds = GetContactName(); repeaterGroup.DataSource = ds; repeaterGroup.DataBind(); } I am not able to access LoadData from GetContactName(). Any help on this would be greatly appreciated.
------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates
you're not a beginner, but you want to know how to call a non static method from a static method ? The only way to do this, is to have an instance of the class that contains the non static method. However, as your control is within a page lifecycle, you can't just create a page instance from out of nowhere, it won't create the lifecycle you need, as a page is not being requested. Therefore, it cannot be done, you need instead to create a page lifecycle, and call your method within that lifecycle. Otherwise, there's no chance you're going to see anything appear in your page.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.