0

I'm in a huge bind.

Long story short, I am working on a big project and am learning ASP.NET, C#, everything as I go.

The elementals of my project are comprised of user controls. My line of thinking was that I could create many user controls, each performing a function for a "component" of the project I'm building. Up until now I have been using clientside scripting to postback ajax calls to the code-behind on each of my user controls. AJAX worked well because it allowed to me pass data(that I need from the client) to my user controls and then I could return something in order to do an action.

I have been using a method for generating querystrings to create a callback "action" in order to determine what method needs to handle what data when the postback is sent to the code-behind side.

My problem now is that I need to start using many user controls one page -- and so now whenever ANY control does a postback ALL of the controls go through a page load. I thought my callback solution would take of this, but it isn't. Particularly when I drop a custom registered control into another user control.

I have done multitudes of research and having seen various ways to get around this, the best of them being [WebMethod] and controllers. However the project I am working on is NON-MVC.

I am also attempting to use UpdatePanel controls to minimize postback to the entire page but have had little success.

What can I use as alternatives? I feel like I'm running out of options or am missing something very basic here.

TL;DR -- I need a non-MVC method to pass data to user controls that can distinguish between multiple controls. Cannot use pagemethods(or page). Manual ajax calls are not working out. Cannot afford to do a full postback

Matt Foxx Duncan
  • 2,074
  • 3
  • 23
  • 38
  • 1
    `[WebMethod]` is an attribute you put on a method that allows it to be used in a Web service. A method marked with the `WebMethod` attribute can be used without (an MVC) controller; it has nothing really to do with MVC specifically. Using the UpdatePanel control might work. Can you perhaps post some code so we can see what you're done thus far? – Patrick Pitre Jul 17 '12 at 21:26

2 Answers2

1

Take a look at:

updatepanel vs page methods

Based on this:

My problem now is that I need to start using many user controls one page -- and so now whenever ANY control does a postback ALL of the controls go through a page load.

This might sound simple but have you tried to use if(!this.IsPostBack) in your load events?

Well not, the only way to avoid this situation, is using PageMethods or create a Script Service to handle AJAX requests (Web services with the ScriptService attribute or WCF REST services)

Note that even if you use the evil UpdatePanel, absolutely all the page life cycle will execute, which means that the whole page viewstate has to be sent in each post, the only advantage of using UpdatePanel controls is that you gain partial rendering, that's it, the performance on the server side doesn't change at all.

So you could use PageMethods or Script Services. But there's a catch, if you start using them you will notice an incredible performance change, your application will be more responsive (RIA applications), but the catch is that you won't be able to use the benefits of the ASP.Net server controls such as GridView, Repeater, etc. In other words you would need to change most of your view controls (this is the approach followed when working with MVC applications)

Community
  • 1
  • 1
Jupaol
  • 21,107
  • 8
  • 68
  • 100
0

You can create static methods on your aspx page and mark it with [WebMethod]. Then you can call the method using jQuery ajax from the user user control markup. Take a look at this blog

Satish
  • 3,020
  • 7
  • 35
  • 47
  • While this is a solution, it won't work for my situation. I am using [Sitecore](http://www.sitecore.net/) for this project and all aspx pages are created dynamically when the page is requested. My only options are user controls. – Matt Foxx Duncan Jul 18 '12 at 12:46