Solved

Adding Attribute after comile returns '

Posted on 2010-08-19
7
458 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

751 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