Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Access page controls in static method

Access page controls in static method

Scheduled Pinned Locked Moved ASP.NET
questioncsharpjavascriptdatabase
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cocoonwls
    wrote on last edited by
    #1

    Hi all, I am using vs2010 with .net 4.0 and jquery AJAX to call to a static method in code behind. I was success to call it but cant get the page's control. Following is my sample code :

    [WebMethod]
    public static string UpdateContent()
    {
    Page page = HttpContext.Current.Handler as Page;
    TextBox tb = (TextBox)page.FindControl("txt");
    tb.Text = "some string here";
    //others coding here//
    if (db.UpdateTable()){return "success";}
    else { return "failed"; }
    }

    So,my question is how can i access the page's control in my static method? any tips are welcome thanks in advance cocoon

    P 1 Reply Last reply
    0
    • C cocoonwls

      Hi all, I am using vs2010 with .net 4.0 and jquery AJAX to call to a static method in code behind. I was success to call it but cant get the page's control. Following is my sample code :

      [WebMethod]
      public static string UpdateContent()
      {
      Page page = HttpContext.Current.Handler as Page;
      TextBox tb = (TextBox)page.FindControl("txt");
      tb.Text = "some string here";
      //others coding here//
      if (db.UpdateTable()){return "success";}
      else { return "failed"; }
      }

      So,my question is how can i access the page's control in my static method? any tips are welcome thanks in advance cocoon

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      as per my knowledge, we can not access page control inside the webmethod. So you can implement your functionality in different way. Take a look URL: http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx[^] If your requirement is different then let me know.

      Parwej Ahamad

      C 2 Replies Last reply
      0
      • P Parwej Ahamad

        as per my knowledge, we can not access page control inside the webmethod. So you can implement your functionality in different way. Take a look URL: http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx[^] If your requirement is different then let me know.

        Parwej Ahamad

        C Offline
        C Offline
        cocoonwls
        wrote on last edited by
        #3

        thanks so much..i will look at it now :laugh:

        1 Reply Last reply
        0
        • P Parwej Ahamad

          as per my knowledge, we can not access page control inside the webmethod. So you can implement your functionality in different way. Take a look URL: http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx[^] If your requirement is different then let me know.

          Parwej Ahamad

          C Offline
          C Offline
          cocoonwls
          wrote on last edited by
          #4

          Dear Parwej AHamand, My requirement is bit different in what the article provided. In my situation, i need to pass 1 parameters to code behind (ideally is to .aspx.cs . Currently i am using webmethod.) and then do some checking with assist by most of the page's controls. For example, pass parameter "Save" to .aspx.cs , then get 10 textbox's value in that page to do verification. hope u are understand my concern. Thanks in advance cocoon

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups