Solved

Adding Attribute after comile returns '

Posted on 2010-08-19
7
454 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

26 Experts available now in Live!

Get 1:1 Help Now