How to get controls depending upon the iteration count?
I want to get clientId dynamically depending upon the iteration count e.g
var clientID = "<%=NumericTextBox" + 1 + ".ClientID %>";
var id = document.getElementById(clientID);
but if i try to use above statements to get the control it throws ";expected", ")exppected开发者_StackOverflow社区" errors what is the proper way of getting the control?
I think you have numeric textbox control in asp.net. If you need to get the id of it, you can use
var clientId = '<%= NumericTextBox.ClientId %>';
var txt = document.getElementById(clientId);
If the textbox is inside a grid control, you would usually append the number at the end or at the beginning like this
var clientId = 'ctl_0' + i + '<%= NumericTextBox.ClientId %>'
You can check the id that the framework is rendering by going to view source.
I don't know what server-side language and template engine you're using, but I think you're using it incorrectly and that's what's giving the error. In most languages, this will parse as a server-side templating directive that executes the following code:
NumericTextBox " + 1 + " .ClientID
Which is nonsense in most languages and looks like a mistake in any language I know of. (It's actually possibly valid Ruby, but probably not correct Ruby since Strings don't normally have a ClientID
method.)
var clientID = '<%=FindControl("NumericTextBox" + "1").ClientID%>';
var id = document.getElementById(clientID);
精彩评论