问题
I understand that I currently can't use <a onclick="alert('<%=TextBox1.ClientID%>')"
directly because I need to access it in a table cell in a table in the EditTemplate of a DataList inside a UserControl.
That said, I need to recursively check the controls to get the ClientID, should it be done
client-side: alert(getMyElement('TextBox1').id)
, where getMyElement checks all elements of the form and returns the control with the id...or
server-side: alert('<%=FindElement(dlDataList, "TextBox1").ClientID%>')
where FindElement is a base page function that checks the controls of the first param for an element with an id of the second param and returns that control
?
I'm figuring the client-side would be faster?
回答1:
I always go with server side for this case. Otherwise you're traversing the entire DOM with each row - depending on the size, it could be a memory hog. Server side takes almost no resources for this.
来源:https://stackoverflow.com/questions/1589548/search-for-clientid-client-side-or-server-side