How To Find And Modify An Asp.net Control With JavaScript?
Solution 1:
The problem is that you have set visible=false
on this line
<table runat="server" id="tblLottoPick" visible="false">
From that moment the controls are not rendered the javascript can not find this control. If you do not wish to show this table use css, for example style="display:none;"
so its rendered but not visible. All the rest seems to me that working.
Update
From the comments also seems that this code is not inside the aspx page, so the ClientID can not work and not found. Add this somewhere in the header in the page that have this LoginView1 control.
function validateLottoPicks() {
document.getElementById('<%= LoginView1.FindControl("txt2ndNum").ClientID %>').value = 12
}
Solution 2:
Try
tblLottoPick.FindControl("txt2ndNum").ClientID
instead.
Solution 3:
Try putting this into a javascript string variable. What are you getting?
'<%= LoginView1.FindControl("txt2ndNum").ClientID %>'
Because you shouldn't have to do that. Can you just do this?
document.getElementById('txt2ndNum')
Also, check in firebug to see what the ID value is set to for that control (i.e. the rendered textbox). I mean see what it's rendered as. You just need to get the right id.
Post a Comment for "How To Find And Modify An Asp.net Control With JavaScript?"