Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Question about quotes and apostrophes when using javascript in c#

Posted on 2007-11-16
9
Medium Priority
?
1,009 Views
Last Modified: 2008-02-01
I have this code and just need to know how the quotes and apostrophes go when using javascript in c#:

It works until I add the  <input id=finish type=button value=Finish style=width: 165px onClick=window.location=default.aspx/>  I think it is failing at the window.location=default.aspx bit.

div_input_form_change_innerhtml += "   '<table width=100%><tr><td align=center>Your application has been received.<hr /></td></tr><tr><td align=right><input id=finish type=button value=Finish style=width: 165px onClick=window.location=default.aspx/></td></tr></table>';   ";

Thanks
0
Comment
Question by:scanet
  • 5
  • 3
9 Comments
 
LVL 16

Expert Comment

by:McExp
ID: 20300160
<input id="finish" type="button" value="Finish" style="width: 165px;" onClick="window.location=default.aspx;" />
0
 
LVL 9

Expert Comment

by:hismightiness
ID: 20300250
This is kind of splitting hairs, but this would be better as:
div_input_form_change_innerhtml += "<input id=\"finish\" type=\"button\" value=\"Finish\" style=\"width: 165px;\" onclick=\"window.location='default.aspx';\" />";

Open in new window

0
 

Author Comment

by:scanet
ID: 20300663
Nither worked im affraid:

the div_input_form_change_innerhtml += " " is c# and I want to put this into it:

'<table width=100%><tr><td align=center>Your application has been received.<hr /></td></tr><tr><td align=right><input id=finish type=button value=Finish style=width: 165px onClick=window.location=default.aspx/></td></tr></table>';

as I said if I just put this into it, it works fine:

'<table width=100%><tr><td align=center>Your application has been received.<hr /></td></tr><tr><td align=right></td></tr></table>';

But when I add the button and try to put in the windowslocation it needs quotes but is not working I thought you had to add multiple quotes and apostrophes to get it to work but dont know the combination.

Thanks

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:McExp
ID: 20300907
What is contained in "div_input_form_change_innerhtml" before you append the string?
0
 
LVL 16

Expert Comment

by:McExp
ID: 20300953
In my first example the string was not escaped, as I wasn't sure exactly what you where trying to do.

Making the assumption that you are trying to create a javascript command that sets the innerhtml here is a solution that might work.

div_input_form_change_innerhtml += " '<table width=\"100%\"><tr><td align=\"center\">Your application has been received.<hr /></td></tr><tr><td align=\"right\"><input id=\"finish\" type=\"button\" value=\"Finish\" style=\"width: 165px;\" onClick=\"window.location=''default.aspx'';\"/></td></tr></table>';";

I have used escaped double quotes to get them into the c# string and then two single quotes arround the default.aspx to escape that for when it reaches your javascript.
0
 

Author Comment

by:scanet
ID: 20301041
Still not working, it is saying that it is expectiing a ; ,here is the whole peice of script with your latest answer McExp:

// Define the JavaScript function for the specified control.
string div_input_form_change_innerhtml = "   <script language='javascript'>document.getElementById('div_input_form').innerHTML =   ";

div_input_form_change_innerhtml += "  '<table width=\"100%\"><tr><td align=\"center\">Your application has been received.<hr /></td></tr><tr><td align=\"right\"><input id=\"finish\" type=\"button\" value=\"Finish\" style=\"width: 165px;\" onClick=\"window.location=''default.aspx'';\"/></td></tr></table>'; ";

div_input_form_change_innerhtml += "   </script>   ";

// Add the JavaScript code to the page.
ClientScript.RegisterStartupScript(typeof(Page), "div_input_form_change_innerhtml", div_input_form_change_innerhtml);
0
 
LVL 16

Expert Comment

by:McExp
ID: 20301131
Where do you get the expecting ; error is it in the browser or on compile?

One thing to note, you should use this.GetType() instead of typeof(page), in most cases it will always return the same, however if you ever use an alternative class derived from page it will be setting it as the wrong type.

ClientScript.RegisterStartupScript(typeof(Page),
0
 
LVL 16

Accepted Solution

by:
McExp earned 200 total points
ID: 20301199
The following should work for you:

        string div_input_form_change_innerhtml = "document.getElementById('div_input_form').innerHTML = '<table width=\"100%\"><tr><td align=\"center\">Your application has been received.<hr /></td></tr><tr><td align=\"right\"><input id=\"finish\" type=\"button\" value=\"Finish\" style=\"width: 165px;\" onClick=\"window.location=\\'default.aspx\\';\"/></td></tr></table>'; ";

        // Add the JavaScript code to the page.
        ClientScript.RegisterStartupScript(this.GetType(), "div_input_form_change_innerhtml", div_input_form_change_innerhtml,true);
0
 

Author Comment

by:scanet
ID: 20301410
Thanks McExp that worked a treat.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question