How to access or refer a server control like gridview in static WebMethod in server-side

Last post 05-30-2008 5:12 PM by vgiambattista. 19 replies.

Sort Posts:

  • How to access or refer a server control like gridview in static WebMethod in server-side

    05-02-2008, 4:30 AM

    Hello experts,
      I have an Ajax page in which on a client side code, I call a PageMethods statement to get the result from a static server-side WebMethod (webservice function) function on the page itself on server side. I'd like in that static server-side WebMethod I am able to access a gridview control which already declare on the markup part of my Ajax page. Howevver,I always get the error like "a static function tried to access non-static object or variable ...."
      Please give me any idea to get through this problem since I's like to access or refer the gridview control on that server-side WebMethod?
    Thank you in advance.
    johnaspnet

  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-02-2008, 7:22 AM

    Static methods are not related to any instance of the class. So you cannot access any member variable(gridview) from a static function in the page. Instead use a non static method if you want to access the gridview in the page

    Vikram
    www.vikramlakhotia.com
    justlikethat.vikramlakhotia

    Please mark the answer if it helped you
  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-02-2008, 9:04 AM

    Vik2000, thanks for your reply. However, by the definition on the server side of a webmethod, I must use the method as a static one. For example,
    [WebMethod]
    public static String myPageMethod(String arg)
    {

        .... 
    }

    So how can I use a non-static web method to access my gridview?

  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-02-2008, 9:04 AM

    Vik2000, thanks for your reply. However, by the definition on the server side of a webmethod, I must use the method as a static one. For example,
    [WebMethod]
    public static String myPageMethod(String arg)
    {

        .... 
    }

    So how can I use a non-static web method to access my gridview?

  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-02-2008, 9:15 AM
    Answer
    • Loading...
    • mrmercury
    • Joined on 04-04-2006, 6:26 PM
    • Mexico City, Mexico
    • Posts 277
    You can’t access the controls in your page from a webservice or from a page method, you have to remember that the webservices resides in your server and at this moment the gridview resides in the browser on the client’s side, in ASP.NET Ajax webservices are meant to receive and return data that can be manipulated by the client using JavaScript, you can use the updatepanel to do what you are trying to do.
    If this post helped you please remember to set it as Answer so it can help others.
  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-02-2008, 9:35 AM
    Thank you for your idea. If I use UpdatePanel control, how can I trigger it using an HTML control event like <input type=textbox onkeyup="how_I_trigger_updatePanel_here???" > ? I know how to trigger the UpdatePanel by using server control like a button but it causes a PostBack on the UpdatePanel.
  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-08-2008, 6:09 AM
    Answer

    Use javascript to trigger the updatepanel:

    http://encosia.com/2007/07/13/easily-refresh-an-updatepanel-using-javascript/

    Best Regards, 

    Sincerely,
    Jin-Yu Yin
    Microsoft Online Community Support
  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-08-2008, 1:53 PM

    Thank you Jin

  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-09-2008, 10:02 AM

    Thank you, Jin.
    The method on

    http://encosia.com/2007/07/13/easily-refresh-an-updatepanel-using-javascript/

    causes the whole-page post back. Is there any way to use javascript to trigger UpdatePanel in partial postback way instead whole-page posback to reduce overhead for the aspx page?

    Thank you in advance.
    johnaspnet

  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-12-2008, 8:37 AM

    Thank you, Jin.
    The method on

    http://encosia.com/2007/07/13/easily-refresh-an-updatepanel-using-javascript/

    causes the whole-page post back. Is there any way to use javascript to trigger UpdatePanel in partial postback way instead whole-page posback to reduce overhead for the aspx page?

    Is there a better way to go with partial postback using client side codes?
    Thank you in advance.
    johnaspnet

  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-14-2008, 8:27 AM

    Give me any idea please? Thanks very much.
    johnaspnet

  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-14-2008, 9:29 PM

    It should be partial postback.

    Sincerely,
    Jin-Yu Yin
    Microsoft Online Community Support
  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-15-2008, 8:16 AM

    If it is a partial postback, then how can I use an HTML control (not server control) like a button to trigger an UpdatePanel server control for such partial postback? Can you please give me any sample code for such?
    Thank you very much.
    johnaspnet

  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-15-2008, 9:58 PM
    <div id="Container" onclick="__doPostBack('UpdatePanel1', '');">

     

    Sincerely,
    Jin-Yu Yin
    Microsoft Online Community Support
  • Re: How to access or refer a server control like gridview in static WebMethod in server-side

    05-16-2008, 10:58 AM

    Hi Jin-Yu
    Thank for your reply.
    My question for you is if you call  __doPostBack('UpdatePanel1', ''), then you make the entire-page postback or a partial postback for the UpdatePanel control only? It seems to me that __doPostBack does the whole postback and costs overhead, does n't it? Please let me know.
    johnaspnet

Page 1 of 2 (20 items) 1 2 Next >