Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Getting StartedGetting StartedProglem adding javascript from code-behindProglem adding javascript from code-behind
Previous
 
Next
New Post
11/18/2010 8:13 PM
 
I am new to ASP.net and DNN module development.  I have creating a working module, and would like to inject javascript into the page via the server-side code-behind event handler for a Button.  I am successfully injecting javascript in the Page_Load event using RegisterClientScript, but when I try the same technique in a Button event handler, I can see using the brower's view-source that the javascript is not being written to the page.

I don't know if this is an ASP.Net page build life-cycle issue, or a DNN-specific issue.  Can anyone point me in the right direction?
 
New Post
11/23/2010 1:16 AM
 
There will always be complications and potential for conflicts when adding JavaScript to the page via a postback event.  You're almost better off doing this via a client-side event.  Mitch Labrador has a good script that can help you create your own similar script to do this:

http://mitchlabrador.com/2010/11/12/h...

I know it's not an exact duplicate of what you're trying to do, but it should help just the same.

Will Strohl

Upendo Ventures Upendo Ventures
DNN experts since 2003
Official provider of the Hotcakes Commerce Cloud and SLA support
 
New Post
11/23/2010 11:52 PM
 
Thanks for your reply.  The specific reason for my question is that I have a tall input form and In a button postback event handler I am doing server-side validation, and then displaying error messages using DotNetNuke.UI.Skins.Skin.AddModuleMessage().  In Firefox, Opera, Chrome, & Safari the returned page is scrolled to the top so that the AddModuleMessage display is visible without scrolling - even when scrolled to the bottom of my tall form when the button is clicked.  In IE however, if I click the button while scrolled to the bottom of the form, the  DNNModuleMessage at the top is not in view, so it would be easy to miss the error message display.  I had hoped to insert some javascript in the button event handler to cause the page to scroll to the top so the AddModuleMessage display would be visible.

 
New Post
11/24/2010 10:48 AM
 
You can use the aforementioned method of adding scripts, and have that attached to you linkbutton, like so:

jQuery(document).ready( function(){

jQuery('#linkbuttonid').click( function(){

// call your scroll event here

});  });

Then, incorporate your scroll logic.  There are some jQuery plugins that allow you to do this.

Will Strohl

Upendo Ventures Upendo Ventures
DNN experts since 2003
Official provider of the Hotcakes Commerce Cloud and SLA support
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Getting StartedGetting StartedProglem adding javascript from code-behindProglem adding javascript from code-behind


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out