mack28
mack28

Reputation: 129

too many characters in character literal in asp.net c#

Facing difficulties: i'm looking for popup window for chat application in asp.net-c#

   protected void Page_Load(object sender, EventArgs e)
     {
         System.Text.StringBuilder sb = new System.Text.StringBuilder(); 
         sb.Append("<script language='javascript'>function Open() {"); 
         sb.Append(string.Format("window.open('Chat.aspx?rid={0}'",lstRooms.SelectedValue));
         sb.Append(, 'newwindow','toolbar=no,location=no,menubar=no,width=290,height=330,resizable=no,scrollbars=no,top=350,left=980,right=500'");return false;"); 
         sb.Append("}</script>"); 

here is

    if (!ClientScript.IsClientScriptBlockRegistered("JSScriptBlock")) 
    {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "JSScriptBlock", sb.ToString()); 
    }

    if (!ClientScript.IsClientScriptBlockRegistered("JSScriptBlock")) 
    {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "JSScriptBlock", sb.ToString()); 
    }

i got error...too many characters in character literal...in this line

sb.Append(, 'newwindow','toolbar=no,location=no,menubar=no,width=290,height=330,resizable=no,scrollbars=no,top=350,left=980,right=500'");return false;"); 

thnks for guidence

i updated my question as above....plz help me

Upvotes: 2

Views: 8671

Answers (3)

Rajeshkumar
Rajeshkumar

Reputation: 75

While linking the stylesheet/javascript/jquery avoid using runat="server" inside the tag.

If we include runat="server". It may also leads to the above mentioned error.

Upvotes: 1

Hans Kesting
Hans Kesting

Reputation: 39284

The error message points to a specific error: in C# you need to enclose strings in double quotes. Single quotes are used to mean a single character.

string mystring = "This is a test";
Console.WriteLine(mystring[0] == 'T'); // prints "True"

According to the compiler you tried to enclose a string in single quotes.

Upvotes: 1

MUG4N
MUG4N

Reputation: 19717

Here you can find a very easy and nice tutorial for popup with asp.net and ajax:

http://www.asp.net/web-forms/tutorials/ajax-control-toolkit/modalpopup/launching-a-modal-popup-window-from-server-code-cs

Hope it helps you.

Greetings

UPDATE:

this code is tested and works fine:

HTML:

<asp:Button ID="Button1" runat="server" OnClientClick="JavaScript:Open()" Text="Button" />

C#

 protected void Page_Load(object sender, EventArgs e)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<script language='javascript'>function Open() {");
            sb.Append(string.Format("window.open('Chat.aspx?rid={0}'", lstRooms.selectedvalue));
            sb.Append(", 'newwindow','toolbar=no,location=no,menubar=no,width=290,height=330,resizable=no,scrollbars=no,top=350,left=980,right=500');return false;");
            sb.Append("}</script>");

            if (!ClientScript.IsClientScriptBlockRegistered("JSScriptBlock"))
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "JSScriptBlock", sb.ToString());
            }
        }

Of course you have to add the OnClick Attribute to your html button and point to the Open() Method.

Upvotes: 2

Related Questions