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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:27:42+00:00 2026-05-24T06:27:42+00:00

I want to validate two TextBoxes in my WebPage and I want to display

  • 0

I want to validate two TextBoxes in my WebPage and I want to display the Validation Messages in a Message Box. I want to Display these two validation Messages in a New Line.
I did like this:

ErrorMsg="";

if (TextBox1.Text == "")
{
   ErrorMsg += "Name is required!";
   ErrorMsg += "\n";
}
if (TextBox2.Text == "")
{
   ErrorMsg += "Address is required!";      
}

ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), Guid.NewGuid().ToString(), "window.alert('" + ErrorMsg + "')", true);
            return;

But it does not show the message box.

If I remove the coding line
ErrorMsg += “\n”;
in the above code. It simply concatenate the two strings and shows the message box.

How to display in the NewLine?

  • 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-24T06:27:43+00:00Added an answer on May 24, 2026 at 6:27 am

    You will need to escape the newline like below, to stop it being output to the browser as a literal newline:

            string ErrorMsg = "";
    
            if (TextBox1.Text == "")
            {
                ErrorMsg += "Name is required!";
                ErrorMsg += "\\n";
            }
            if (TextBox2.Text == "")
            {
                ErrorMsg += "Address is required!";
            }
    
            ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), Guid.NewGuid().ToString(), "window.alert('" + ErrorMsg + "')", true);
            return;
    

    This should produce the following in the browser:

    window.alert('Name is required!\nAddress is required!')
    

    Where as before this was the output (which was failing because of a newline in the string constant):

    window.alert('Name is required!
    Address is required!')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to validate my email address through jquery unobtrusive validation . Like to
I am having two select box Month,Year (for expire date).I want to validate both
I want to validate some asp.net textboxes with the jQuery Validation plugin found at
i want to validate my form.I have a form validation javascript code in my
i want to validate uniqueness of two filed but if second filed is nil
I want to use ComponentModel DataAnnotations validate that at least one of two properties
I have two websites.I want to validate,if the person who is signing in the
I'm using the jQuery Validation plugin and trying to validate two time fields. I
I want to validate an input of format AB1234 where first two characters must
I want to validate that two fields on a page match (e.g. are 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.