Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Question about quotes and apostrophes when using javascript in c#

Posted on 2007-11-16
9
1,000 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 50 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

791 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