Solved

Adding Attribute after comile returns '

Posted on 2010-08-19
7
456 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now