Solved

Question about quotes and apostrophes when using javascript in c#

Posted on 2007-11-16
9
1,006 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

621 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