Solved

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

Posted on 2014-12-13
3
245 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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to filter by key press ? 6 53
alert on input text 2 23
Debugging Html 8 31
Hta File displays dynamic File names 4 43
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

685 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