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 9114831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:17:20+00:00 2026-06-17T04:17:20+00:00

[WebMethod] public string LoadLayout() { try { List<XmlTag> lstXmlTags = new List<XmlTag>(); lstXmlTags =

  • 0
 [WebMethod]
 public string LoadLayout()
 {
        try
        {
            List<XmlTag> lstXmlTags = new List<XmlTag>();
            lstXmlTags = parser.GetXmlTags(filePath);

            string script = "<script type=\"text/javascript\">alert(lstXmlTags );</script>";
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "test", script, true);

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

I want to alert lstXmlTags for test purpose.Above code run locally but in server its get a problem.I think in server its doesn’t able to get filepath.So I want to alert what lstXmlTags returns or is it empty.So I add RegisterClientScriptBlock for showing result.But what I try gives me syntax error.I am not able to use RegisterClientScriptBlock.Thanks.

  • 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-06-17T04:17:21+00:00Added an answer on June 17, 2026 at 4:17 am

    You seem to be mixing client side variables with server side. Here’s one way you could achieve that:

    [WebMethod]
    public string LoadLayout()
    {
        try
        {
            List<XmlTag> lstXmlTags = parser.GetXmlTags(filePath);
            var serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(lstXmlTags);
    
            string script = string.Format("alert(JSON.stringify({0}));", json);
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "test", script, true);
    
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    

    Things to notice here:

    • I have used a JSON serializer (The built-in JavaScriptSerializer class) to make sure that the server side variable lstXmlTags is properly encoded before passing it to a cilent side function
    • I have gotten rid of the <script type="text/javascript"> tags because you have passed true as last parameter of the RegisterClientScriptBlock function which means (I quote from the documentation): A Boolean value indicating whether to add script tags. So if you set this to true the method will already add those tags for you and you should not be manually adding them once again.
    • I have used the JSON.stringify method inside the alert function. This method is natively built-into all modern browsers and allows to convert a javascript variable definition into a string so that you get a friendly display. But of course you could have directly used the variable if you wanted to: alert({0}[1].SomeProperty); will display some property of the second element in your collection.

    Remark: For debugging purposes it’s far better to use console.log and a javascript debugging tool such as FireBug instead of alerting around with some modal windows.

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

Sidebar

Related Questions

I have following webservice: [webmethod] public string MakeReservation(?? PassengersInfo)//what data type use for PassengerInfo
In my experience I call simple web methods, like this: [WebMethod] public List<string> GetUserListByLetters(string
Code Behind: [WebMethod] public static string emp() { return BlaBla; } Aspx Page: $(document).ready(function()
I have a page with this method in CreateTicket.aspx.cs: [WebMethod()] public static string Categories()
am accessing a class from my webservice as [WebMethod(EnableSession = true)] public string fetchAbsentees(string
<WebMethod()> Public Shared Function micro() As String Dim context As HttpContext = HttpContext.Current Dim
I'm using C# webservice in my webMethod: [WebMethod] public SignUpResponse SignUp(string email, string password)
I have a simple web service operation like this one: [WebMethod] public string HelloWorld()
I am using the following WebMethod- [WebMethod] public string get_IDs(string uid) { string url
I get an error of Cannot convert object of type System.String' to type 'System.Collections.Generic.List'1[...+ContactHolder]'

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.