Search code examples
c#javascriptasp.netgoogle-books

Adding Script to ASPX page


Hi I want to add google book preview button to my website. Its code is something like :

<script> GBS_setLanguage('en');</script>            
<script>GBS_insertPreviewButtonPopup('ISBN:0596009208');</script>

Now the problem is I get the ISBN number from the previous page. So I have to include this in C# code on the page. So how this can be done ? I tried doing it but it just does not compile


Solution

  • Used this code to do what I wanted... But it places the script/ google preview button (in my case) to either header or the footer . But no other way to do this.

             HtmlGenericControl script1 = new HtmlGenericControl("script");
            script1.Attributes.Add("type", "text/javascript");
            script1.Attributes.Add("src", "http://books.google.com/books/previewlib.js");
            this.Page.Header.Controls.Add(script1);
    
            string GoogleScript = "";
    
            string isbncode = "";
            if (Page.Request.QueryString["isbn"] != null)
                isbncode = Page.Request.QueryString["isbn"];
    
            GoogleScript = "GBS_setLanguage('en'); GBS_insertPreviewButtonPopup('ISBN:";
            isbncode = isbncode + "');";
    
            HtmlGenericControl script3 = new HtmlGenericControl("script");
            script3.Attributes.Add("type", "text/javascript");
            script3.InnerHtml = GoogleScript + isbncode ;
            this.Page.Controls.Add(script3);