Click here to Skip to main content
15,884,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
P_Dash 24-Jan-13 5:55am    
Where is that exact string you asked in question dear ?
I can't see it anywhere in the code.
[no name] 24-Jan-13 6:02am    
it will be in thought = ds.Tables[0].Rows[0][0].ToString();
Sandesh M Patil 24-Jan-13 9:26am    
you already resolved the problem by using following function,

public string convertQuotes(string str)
{
return str.Replace("'", "''");
}
[no name] 25-Jan-13 0:50am    
DEAR SIR, BUT IT WILL NOT WORK.

1 solution

Try escape sequence:
C#
public string convertQuotes(string str)
{
   return str.Replace("'", "\'");
}

Refer: MSDN: Escape Sequences[^]
 
Share this answer
 
Comments
[no name] 25-Jan-13 0:52am    
not working............
[no name] 25-Jan-13 1:01am    
my string like......
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";
Sandeep Mewara 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900