Solved

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
grab and show facebook pages event calendars 6 44
angularjs controller not found 1 18
angularls and plnkr 14 18
Asp.net mvc 5 5 19
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now