Solved

Adding Attribute after comile returns '

Posted on 2010-08-19
7
460 Views
Last Modified: 2012-05-10
Good evening,
Ive been trying to add a javascript methods to a textbox on my aspx page. I have used the two lines below to add the javascript functions to the textbox:-
        TextBox1.Attributes.Add("onFocus", "javascript: showDiv(this, 'divBelowObjects');")
        TextBox1.Attributes.Add("onBlur", "javascript: hideDiv('divBelowObjects');")

But when I run the code, it fails with an 'Invlid character' on the following line:-
<input name="ctl00$MainContent$TextBox1" type="text" id="MainContent_TextBox1" onFocus="javascript: showDiv(this, &#39;divBelowObjects&#39;);" onBlur="javascript: hideDiv(&#39;divBelowObjects&#39;);" />

What I dont understand is why asp is converting ' into &#39; ???

Any ideas how I can run my code with ' instead of &#39;???

Thank you
0
Comment
Question by:tonelm54
[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
7 Comments
 
LVL 17

Accepted Solution

by:
Zhaolai earned 250 total points
ID: 33480123
You need to escape it with a backslash \'divBelowObjects\'.


0
 
LVL 14

Expert Comment

by:raja_ind82
ID: 33482745
i think  &#39;, is not a problem. Can you please send us the actual error message or screen shot?


Regards,
Raja Muthaiah
0
 
LVL 16

Expert Comment

by:kris_per
ID: 33484153

Try using double quotes instead of single quotes like:

TextBox1.Attributes.Add("onFocus", "javascript: showDiv(this, \"divBelowObjects\");")

TextBox1.Attributes.Add("onBlur", @"javascript: hideDiv(\"divBelowObjects\");")

0
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 
LVL 16

Assisted Solution

by:kris_per
kris_per earned 250 total points
ID: 33484307
Minor correction in previous comment:

Try using double quotes instead of single quotes like:

TextBox1.Attributes.Add("onFocus", "javascript: showDiv(this, \"divBelowObjects\");")

TextBox1.Attributes.Add("onBlur", "javascript: hideDiv(\"divBelowObjects\");")
0
 

Author Comment

by:tonelm54
ID: 33494836
I have tried:-

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Attributes.Add("onFocus", "javascript: showDiv(this, ""divBelowObjects"");")
TextBox1.Attributes.Add("onBlur", "javascript: hideDiv(""divBelowObjects"");")
End Sub

Which runs as:-

<input name="ctl00$MainContent$TextBox1" type="text" id="MainContent_TextBox1" onFocus="javascript: showDiv(this, &quot;divBelowObjects&quot;);" onBlur="javascript: hideDiv(&quot;divBelowObjects&quot;);" />
0
 

Author Comment

by:tonelm54
ID: 33494845
I have tried:-
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox1.Attributes.Add("onFocus", "javascript: showDiv(this, \'divBelowObjects\');")
        TextBox1.Attributes.Add("onBlur", "javascript: hideDiv(""divBelowObjects"");")
    End Sub


Which runs as:-
<input name="ctl00$MainContent$TextBox1" type="text" id="MainContent_TextBox1" onFocus="javascript: showDiv(this, \&#39;divBelowObjects\&#39;);" onBlur="javascript: hideDiv(&quot;divBelowObjects&quot;);" />
0
 

Author Comment

by:tonelm54
ID: 33494849
When I try:-
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox1.Attributes.Add("onFocus", "javascript: showDiv(this, \"divBelowObjects\");")
        TextBox1.Attributes.Add("onBlur", "javascript: hideDiv(\"divBelowObjects\");")
    End Sub

I get:-
Comma, ')', or a valid expression continuation expected.
0

Featured Post

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

635 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