Blogs

DNN Quick Tip: Ajax Postback Controls

15 Dec

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.  Lets 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:

DotNetNuke.Framework.AJAX.RegisterPostBackControl(btnRunReport);

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!

tags: DNN Development, Quick Tips
comments powered by Disqus

Content provided in this blog is provided "AS-IS" and the information should be used at your own discretion.  The thoughts and opinions expressed are the personal thoughts of Mitchel Sellers and do not reflect the opinions of his employer.

Connect with Mitchel

I hope the information here has been helpful. To stay connected you can also subscribe to blog updates via email, contact Mitchel about consulting services, or reach out for assistance via CodeMendor

Content Copyright

Content in this blog is copyright protected.  Re-publishing on other websites is allowed as long as proper credit and backlink to the article is provided.  Any other re-publishing or distribution of this content is prohibited without written permission from Mitchel Sellers.