Solved

How to register a script at the bottom of a page in C# code behind

Posted on 2014-12-13
3
249 Views
Last Modified: 2014-12-26
Hello,
I the following script. How do i include it at the bottom of my page using code -behind in aspx.


 private string loadDropboxScript()
        {
              string key = ApiKeySettings.DropboxAppKey;
              StringBuilder sb = new StringBuilder();
              sb.Append("<script type='text/javascript' src='https://www.dropbox.com/static/api/2/dropins.js' id='dropboxjs' data-app-key=");
              sb.Append("'").Append(key).Append("'").Append("></script>\n");
              return sb.ToString();
        }

Open in new window

?
I tried to used  ScriptManager.RegisterStartupScript .
ScriptManager.RegisterStartupScript(this, this.GetType(), "dropboxdriveScript", loadDropboxScript(), true);

Open in new window


However, it  adds  the script but it place it within  another script type.. Is that valid?

<script type="text/javascript">
//<![CDATA[
<script type='text/javascript' src='https://www.dropbox.com/static/api/2/dropins.js' id='dropboxjs' data-app-key='mmmmmm'></script>

Open in new window


Here is what I tying to accomplish. I want to add dropbox.js to my page and a dropbox picker. However, this service is block in  some network.So, my page load for a while if Drop Box is not allow. I would like to only incur this penalty when the button is press or have include everything has been loaded

Thanks
0
Comment
Question by:SiemensSEN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40497878
Why do you need to add it from the code behind?

If there's something you want to use from the code behind you can simply inject it with the server side tags :
<%=...  %>

Open in new window

0
 

Author Comment

by:SiemensSEN
ID: 40499094
Thanks for your response..

I have an application that uses dropbox. However, on some networks this application block. I want to check if dropbox in enable  and then add the script. Otherwise my application just 'hang' until timeout is reach
0
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 40499232
That validation is done in Javascript or server side?

If it's in Javascript just add it to the script before performing the action.
If it's server side, consider adding a flag on an hidden field for instance, that you can use client side to know if you can connect to Dropbox or not.

This way the script can always be there, and you can even move it to a js file like it should.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Open grouped links on a page in new tabs via jquery 5 61
Multiple of Image Swaps 5 41
Add Rows on a Table 8 51
Json and ajax javascript 24 23
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question