Why are the page components unavailable when calling the client a server method with the help of PageMethods?



  • There's an aspx page, the button is html coded with the help of LiteralControl. There is a certain bulb (input), depending on the number of records in the bud. At a certain input, the server method Test is challenged with the help of PageMethods. Here's the method:

    [WebMethod] [System.Web.Script.Services.ScriptMethod]

        public static void Test(string ic1) 
        {            
          new main().Label1.Text = "123"; //main - это имя класса страницы       
        }
    

    It's being performed, but it's an exception to "The reference to the object doesn't point to a copy of the object." These components are posted in UpdatePanel so that the page is not updated. ♪ ♪ The difficulty is, you can't use a response.redirect c get-request, because I need a page not overloaded... So we have to use PageMethods. What's the problem? Why is Label1 unavailable or is it necessary to cause it differently in this case (class main nucleus not static) ? The question is how to address the non-statistical properties of the same class, or is that not possible? Thank you.



  • Statistic methods do not have access to a specimen of the class, and you will not be able to do what you're thinking. You've made some kind of label on the statistical page (it's probably NIL at the time of the treatment) and if you even manage to make it, the browser page doesn't know anything about it and nothing happens.

    Web-based techniques are usually around the following: you call a web-based memo from Javascripta, and then you get a result from the server, and then, with the same Javascrip, you update the necessary DOM features of the page model.

    But since you're using the panel, that's another simpler option: you put all the planned updates into the panel, add the same button and create a server for the button, where you'll be able to access the common page elements, and the page will be updated, as you're planning without additional javascripotum, and the main reboot, The button doesn't have to be placed in a panel, but it's necessary that everyone still work, too, to add a trigger to the panel about the click button.

    UP: The first dynamically adding the counters on the page is necessary in the event of the Init before loading the viust. Secondly, if your first button is server and server processing, and is placed in a peddler, when processing an axe request from it, Load's event is working, but the server of the button is already working on the skylight of the load and, therefore, creating other buttons late. It can be done, but it's necessary to think about some parameters of the event, etc., so that you can on Inith already determine that there is a need to generate more server buttons and then everything will work. But, as I wrote a few times, you don't need a panel in a client code. You're making a request for a web-based memo (for example, he's returning a ring-to-snoop, which you need to create) and in a Javascript you're making customer buttons! I mean, you have two paths of development-- pick anyone and use it.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2