Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Dear All,
 
I have a string like "Hello how`s you". when this string is come and used in scriptmanager for pop up it will not work.
 
but when i remove the "`s" from string so it works perfact.
 
so, how can i resolved this problm.
 
my code:
 
 
  string s = "select thought from thought_of_month";
            SqlDataAdapter ad = new SqlDataAdapter(s, c.getcon());
            DataSet ds = new DataSet();
            ad.Fill(ds);
 
            if (ds.Tables[0].Rows.Count != 0)
            {
                thought = ds.Tables[0].Rows[0][0].ToString();
                //thought = "hello";
                try
                {
                    
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('" + convertQuotes(ds.Tables[0].Rows[0][0].ToString()) + "');window.location ='User_Home.aspx';", true);
                }
                catch (Exception e1)
                {
                    e1.Message.ToString();
                }
-----------

 public string convertQuotes(string str)
    {
        return str.Replace("'", "''");
    }
 
 
please help me......
 
Thanks and Regards....
Mitesh
Posted 24-Jan-13 0:36am
Comments
Gittu Dash at 24-Jan-13 5:55am
   
Where is that exact string you asked in question dear ?
I can't see it anywhere in the code.
SChristmas at 24-Jan-13 9:26am
   
you already resolved the problem by using following function,
 
public string convertQuotes(string str)
{
return str.Replace("'", "''");
}

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try escape sequence:
public string convertQuotes(string str)
{
   return str.Replace("'", "\'");
}
Refer: MSDN: Escape Sequences[^]
  Permalink  
Comments
Sandeep Mewara at 25-Jan-13 2:52am
   
try:
thought = @"The best attitude towards life is 'Yes, I have made lots of mistakes in my life! Because, life doesn't come with User's Manual";
OR
thought = "The best attitude towards life is \'Yes, I have made lots of mistakes in my life! Because, life doesn\'t come with User\'s Manual";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100