Link to home
Start Free TrialLog in
Avatar of Rickzzz
Rickzzz

asked on

ASP Control - Change Attribute Dynamically from VB.Net result

Need to change an attribute on an asp control based on the result of a vb.net query. My feeble stab at it is below. Can someone assist on the correct way? Thanks!!

<td><asp:TextBox ID="HomePhone" MaxLength="12" runat="server" TabIndex="4" <%If not errormsg = "" Then %>BorderColor="#990033"<%End If %> /></td>
Avatar of Padre_Corleone
Padre_Corleone
Flag of United States of America image

not sure if i understand, you want to access the attributes of a textbox control?

if so you can do this on codebehind:
HomePhone.Attribute.Add("MyAttribute","something")
you can also remove attributes:
HomePhone.Attribute.Remove("MyAttribute")
Avatar of Rickzzz
Rickzzz

ASKER

I'm not using a codebehind page. How would I do that just wrapped in <%  %>

If the control is blank then 'errormsg' is populated:

<%
    If Request.Form("submit") = "Next" Then
        Dim is_ok = True
        If Request.Form("HomePhone") = "" Then
            is_ok = False
            errormsg = errormsg & "Home Phone is required<br />"
        End If
%>

The user returns to the form and that error message is written out above the form.

I also want to 'light up' the Home Phone control so the user can easily focus on it. There is other required information as well gathered in the form.

This is obviously incorrect, but shows want I want to do:
<td><asp:TextBox ID="HomePhone" MaxLength="12" runat="server" TabIndex="4" <%If not errormsg = "" Then %>BorderColor="#990033"<%End If %> /></td>

Just trying to find out how to do this correctly.

Thanks!!
try this code below

HomePhone.Attributes.Add("value", "your dynamic content");
ASKER CERTIFIED SOLUTION
Avatar of Padre_Corleone
Padre_Corleone
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
Avatar of Rickzzz

ASKER

<script type = "text/javascript">
<!--
function hide(x) {
document.getElementById(x).style.display='none';
document.getElementById(x).value='';
}
function show(x) {
document.getElementById(x).style.display='';
}
//-->
</script>