Back to all posts

DNN Quick Tip - AJAX Postback Controls

Posted on Dec 15, 2014

Posted in category:

In an effort to get more regular content out here to the blog I am going to try and resume my "Quick Tips" posts. These are much shorter posts than some of the more involved ones that I do but cover common questions and tips that I get via email. A very common request that I get from developers after they have set the "SupportsPartialRendering" flag within their module manifest is how can they set a control to force a postback quickly & easily. Let's investigate!

Traditional ASP.NET

In traditional ASP.NET you would simply edit the "ScriptManager" object within your aspx page and set the control in question to be a PostBack Control. You need to do this if you are modifying the request headers or other advanced operations such as forcing a full page update. (In my case it is often forcing a report down to the client.)

Why DNN Is Different?

Most developers when working with DNN will use the simple route to wrap a module for AJAX updates, simply setting the <supportsPartialRendering>true</supportsPartialRendering> element in your .dnn manifest will result in a much better user experience. But this poses an interesting problem as you do not have a script manager that you can quickly tweak.

How to Register in DNN

A simple google search for "AJAX Postback Control DNN" returns a number of creative solutions. Some of these instruct you to do a bunch of extra work that just isn't needed. To register a control as a postback control it is a 1 line DNN API call:

Register btnRunReport for Postback

In this case, we are setting btnRunReport to cause a postback. That's it, no grabbing special references to the controls, no complex manual wrapping of your control in an UpdatePanel. Just a simple API call.

Hope this was helpful!