This blog explains how we can replace the dynamic control ids with the static once.
Many times we come across code where the developer has used dynamic control names. For example:
- document.getElementById('_ctl8_Attachment').value = textBoxVal;
Cause: The control name changes dynamically at runtime and so the required element is not found by the browser.
Solution
Set the ClientID mode when creating the control.
- <asp:TextBox ID="Attachment" runat="server" ClientIDMode="Static" ></asp:TextBox>
- document.getElementById('Attachment').value = textBoxVal;
Join the conversation! Your thoughts help the community grow.