Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

Adding Attribute after comile returns '

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
ASKER CERTIFIED SOLUTION
Avatar of Zhaolai
Zhaolai
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i think  &#39;, is not a problem. Can you please send us the actual error message or screen shot?


Regards,
Raja Muthaiah
Avatar of kris_per
kris_per


Try using double quotes instead of single quotes like:

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

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

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tonelm54

ASKER

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;);" />
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;);" />
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.