Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Question about quotes and apostrophes when using javascript in c#

Posted on 2007-11-16
9
Medium Priority
?
1,007 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
[X]
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
  • 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
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.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

719 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