Load user control and handle post back in ASP.Net - asp.net

I'm working with ASP.NET 3.5 C#
I've seen a good few questions like this around but havn't actually come across any articles with the answer (maybe just been unlucky with my research!).
Basically I'm looking to have say 3 links (or buttons) on a page, which in turn will dynamically load a specific user control into an update panel with AJAX.
Then I would like the usercontrol loaded to be capable of handling postback within the update panel (basically no page refreshes) to do its processing and return output.
Is this possible?
Does anyone have any pointers to articles/blogs covering this?
I've seen many, but none covered handling postbacks from the user control or handling the postbacks within the update panel.
I may even have the wrong end of the stick here.
Any tips would be great to start me off :)
Cheers!

Have a look at this blog post.
It may not be exactly what you want (Postback issue), but can be a good alternative solution to get started with.

Related

POSTing to another page in Umbraco

Alrighty, I've asked this question of Umbraco forums and Umbraco support, let's see who wins the race if I ask stackoverflow too. =)
ASP.net provides several options for posting data to another page or usercontrol within your site, but they all seem to fail within Umbraco (at least that's how it seems when reading through Umbraco forum posts or trying them myself).
I've tried using PostBackURL, but it's not-recommended in a couple of
forum posts, and it seems to break the onclick of the other buttons on the page.
I've tried using Server.Transfer, but it doesn't seem to work in a
handler like Button onclick.
I can't use Response.Redirect and put data in the GET query string,
because there's a big chunk of data to transfer ... I need to POST.
Is there a recommended way of doing this for an Umbraco site?
So If I understand your question correctly, you are trying to import / use an ASP .Net user control with umbraco? And the question is around you having issues trying to achieve this?
If so please comment on this answer and I will update with a solution.

asp mvc appropriate ajax usage

I realized that many of my past projects have suffered from "too much ajax". I write pretty much all intranet "business" type apps so accessibility to older browser/disabled javascript/etc has never really been much of an issue for me. But things like unable to bookmark/go back/random errors/timeouts that the user doesn't see (I know there are ways around this but just as an example)...and most of all the development time is a lot longer (big issue for me I'm the sole dev) for what seems to be not a whole lot.
From people's experience - when is it appropriate to use ajax in business app/mainly CRUD type sites?
Take this as an example: I have a grid displaying all the registered users. One of the buttons takes you to an edit/details view where you can edit all the info and view further info not displayed on the grid. You can click "save" an ajax request is made and return either a success message or a modelstate with errors converted to JSON and that is displayed in a message above the "save" button (with a bunch of jquery that parses the result) all nice without a page refresh. I have many many screens similar to this. Would it make more sense just to redirect back to the grid displaying all the users once "save" is clicked and successful (with some sort of "flash message" on top stating save was successful) skipping all the ajax/json/etc? As the dev. I have a hard time imaging what would make most sense to the end users, but just doing a redirect would be much simpler and makes sense to me. What are people's experiences in these sort of scenarios?
In that scenario I would avoid AJAX all together unless you have a specific reason for it. Partial page updates, keeping a user's place on the page, or other reason.
MVC handles the scenario you describe very well, including the success/failure messages. In this "edit" failure case you'll detect the failure server side and return the same edit view back to the user with model state information. All of their fields will remain populated and you'll easily be able to display validation messages. On the success side you will return your list or index view and possibly use TempData to display a message to the user indicating their successful edit. A little javascript to spice that up and remove the message after 10 seconds or so and the user experience is very good.
This gets even better when you add client side validation, which is much easier in MVC3.
I think you can create a very intuitive experience for the user in this case and avoid ajax/json all together. I do both but I make sure I have a legitimate reason before I start writing client side ajax code.
Take a look at the Steve Sanderson MVC books. He walks through this scenario exactly as you described with good detail. His MVC3 book isn't out yet, and I haven't read the MVC2 book but the original MVC book has it.
http://www.amazon.com/ASP-NET-Framework-Experts-Voice-NET/dp/1430228865/ref=sr_1_4?ie=UTF8&qid=1308745293&sr=8-4
I also like PluralSight online training when I'm looking for fundamental framework guidance like this. http://www.pluralsight-training.net/microsoft/
Of course there are plenty of free blogs and what not that cover MVC too. Have fun.
In my application where I have to take a lot of data from the user that happens mostly form main business entities (Employeee, Distributor, etc.) I usually take the route of normal form post rather than ajaxifying the form. Mostly, I use ajax when data to be posted is small and I have to display data on same page after saving.
For instance, on Employees view page you can have a little form to add experiences for the employee and you can save it through ajax and append the entered data back to the same page.
Take the example of Stack Overflow for instance. They use normal form post for saving answers and questions but when it comes to comments where amount of data is small and comments have to be appended on the same page then it makes sense to use ajax in such scenarios.

ASP.NET website structure / flow

ASP.NET, web form model.
Is there any sample code/site that demonstrate a couple samples for regular website patterns/ templates? Like if I want to use tab to switch between different pages, should I put the code in a single page or in different page, and treat each tab as a page.
Or if in a search page (just a single search bar and button), should I display my result panel in same page using dynamically enable the result panel, or just to another page?
I want to find a general design pattern/ template. Please advise, thanks.
I don't know if this answer will be helpful to you or not. Correct me if I am wrong.
You are specifying demonstration about web designing. It seems the functionality you want is clearly saying to choose from weather you want to use AJAX or not. I suggest why don't you use jQuery Framework for all this functionality.
I would give this a read and consider what best fits your application and your programming style, no one size fits all with paterns.
http://msdn.microsoft.com/en-us/magazine/dd252940.aspx
After you have a general idea, head over to google.com and look for the patterns that catch your eye for simple tutorials
Edit:
For the specific question about whether you should modularize your code. The answer is almost always yes. If you think there is a chance that the component will be used somewhere else then doing this a head of time can save you a lot of headache later. This practice also makes maintaining a lot easier because it gives a clear scope of what could be causing a bug. Instead of having to look threw an entire page of unrelated code for things changing state unexpectedly in the page life cycle.

Telerik Rad Combo and async postbacks in asp.net

it looks like nobody has posted on this.
I have a very typical set up, an ajax update panel is updated when a drop list of offices changes. Each form could have it's own values, for instance each store will have it's own list of employees. Here is where the fun begins. The form can be changed by the drop down (new office) or validated and submitted.
On drop down change, I create a new instance of the same rad combo, bind it to the current data, confirm that the correct data is bound. Then on the return trip I see selected the default user from the previous user. This is a composite control, and firebug shows me that the value for the "text box" that simulates the combo still has the old value. I'm suspecting onViewStateLoaded, but turning viewstate off for the Telerik didn't help any. II don;t need it anyway, cuz I have to put the selected value in another hidden to make a cross page post on submit. Any ideas before I hack this up really bad? Any will be appreciated.
I would answer your question directly, but I don't have enough info, as I was not able to duplicate the issue here locally.
Have you tried contacting Telerik support, or using their forums? I've found them to be quite responsive, even offer custom dll's for some solutions.
Like Jeff, I have a difficult time rebuilding your scenario from the description. The fastest way to solve this problem is to open a Telerik Support Ticket. If you can provide a basic sample the exhibits the problem, the support team will quickly respond with a solution. Don't miss that valuable part of your Telerik purchase! That's what separates commercial tools from unsupported options.
If you'd prefer to keep troubleshooting, I'd try stepping back and simplifying your scenario. It sounds like some hacking has already begun and I think that may be leading to unusual results.
Specifically, the step where you create a new RadComboBox on post should not be required. If you can share some more code examples, I'll be happy to help further.

ASP.net AJAX Drag/Drop?

I wonder if someone knows if there is a pre-made solution for this: I have a List on an ASP.net Website, and I want that the User is able to re-sort the list through Drag and Drop. Additionally, I would love to have a second list to which the user can drag items from the first list onto.
So far, I found two solutions:
The ReorderList from the Ajax Control Toolkit, which requires a bit of manual work to make sure changes are persisted into the database, and that does not support drag/drop between lists.
The RadGrid from Telerik which does all I want, but is priced far far beyond my Budget.
Does anyone else have some ideas or at least some keywords/pointers to do further investigation on? Espectially the Drag/Drop between two lists is something I am rather clueless about how to do that in ASP.net.
Target Framework is 3.0 by the way.
The Mootools sortables plugin does just that, and best of all, it's free ;)
http://demos.mootools.net/Sortables
This is just personal opinion, but the problem I find with ready-made controls in cases like this is that they are extremely bloated, because they're trying to fit everybody's purpose. If all you need is a sortable list then a simple Scriptaculous list or jQuery list with a quick WebMethod callback should fit the bill quite nicely, and you can obviously stick this into your own user control.
As I say, just my opinion, but I wouldn't go spending money on something that's going to add tons of overhead to my page, when I could spend (literally) 10 minutes writing one for free.
I've evaluated the Telerik grid as well as Infragistics version. In the end we took an approach similar to what tags2k suggested. We just wrote our own javascript and called .Net PageMethods to do the server side work.
We found both of the "out of the box" solutions to be bloated. Unless you put paging in at like 20 records per row they really stunk performance wise.
Checkout Raj Kaimal's ajax control extender:
http://weblogs.asp.net/rajbk/Contents/Item/Display/517
It works like a charm.

Resources