Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4570546
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:22:38+00:00 2026-05-21T19:22:38+00:00

I am currently working on my final thesis.I have a small problem.I need to

  • 0

I am currently working on my final thesis.I have a small problem.I need to pass a HTML block which is a string block to a javascript function.I have to do this from code behind.I have tried it so much I doesnt seem as it is going to work.Here is the code in code-behind:

string htmlFlightDetailsJavaScript ;

In the string there are few div and tables which have class propeties. something like div class=”bla”

ClientScriptManager cs = Page.ClientScript;
StringBuilder csText = new StringBuilder();
csText.Append("fill("+htmlFlightDetailsJavaScript+");");
cs.RegisterStartupScript(this.GetType(), "alert", csText.ToString(), true);

Here is my javascript function:

function fill(b) 
{
   alert(b);
}

Note that my javascript function is on the ~.aspx.

I have tried to pass the string without classes which are in the div and the table in string and it is working.But when I try to pass it with the classes,it does not work.Can anyone help me?

Thank you very much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:22:39+00:00Added an answer on May 21, 2026 at 7:22 pm

    This sounds like invalid Javascript is being generated.

    This hypothesis can be verified with inspecting the actual Javascript transmitted and verifying the entire result, in context, for correctness.

    That is, imagine that this invalid Javascript was generated:

    alert("<div class="I just broke JS" ...>")
    

    To fix this, ensure the strings literals inserted into the Javascript are valid.

    For instance, the above might be written (using the following code) as:

    RegisterClientScriptBlock(JsEncoder.Format(@"alert(""{0}"");", theInput))
    

    …and it won’t break because the string is escaped before. (Take a look at this output and compare: the inserted literal will be still valid Javascript, even with quotes or other characters in the theInput. As an added bonus, </script> to break the code either 😉

    This code is “free to use, modify, sell, whatever”. YMMV.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    
    namespace sbcjc.sei
    {
            public class JsEncoder
            {
                static Regex EncodeLiteralRegex;
    
                // Format a bunch of literals.
                public static string Format (string format, params object[] items)
                {
                    return string.Format(format,
                        items.Select(item => EncodeString("" + item)).ToArray());
                }
    
                // Given a string, return a string suitable for safe
                // use within a Javascript literal inside a <script> block.
                // This approach errs on the side of "ugly" escaping.
                public static string EncodeString (string value)
                {
                    if (EncodeLiteralRegex == null) {
                        // initial accept "space to ~" in ASCII then reject quotes 
                        // and some XML chars (this avoids `</script>`, `<![CDATA[..]]>>`, and XML vs HTML issues)
                        // "/" is not allowed because it requires an escape in JSON
                        var accepted = Enumerable.Range(32, 127 - 32)
                            .Except(new int[] { '"', '\'', '\\', '&', '<', '>', '/' });
                        // pattern matches everything but accepted
                        EncodeLiteralRegex = new Regex("[^" +
                            string.Join("", accepted.Select(c => @"\x" + c.ToString("x2")).ToArray())
                            + "]");
                    }
                    return EncodeLiteralRegex.Replace(value ?? "", (match) =>
                    {
                        var ch = (int)match.Value[0]; // only matches a character at a time
                        return ch <= 127
                            ? @"\x" + ch.ToString("x2") // not JSON
                            : @"\u" + ch.ToString("x4");
                    });
                }
            }
    }
    

    Happy coding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m currently working on a script, and I have the following situation. function somnicefunction()
Currently i'm working on my final year project. In a webpage which loads data
I am a seasoned JavaScript programmer, and am currently working on a project which
I am currently working on a project in which I have to keep track
Im currently working with an API which requires we send our collection details in
I'm currently working on an Android application. I wish to have a GridView on
I'm currently working on a script which extracts data from two sources where one
I am currently working on a MapReduce Job which I am only using the
I'm currently working on an app using MVVM that needs to have some data
I have a small jQuery snippet which animates an image caption, based on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.