javascript - getElementById in separate js file doesn't find ASP.net control -


when have in page markup works fine:

<script type="text/javascript">     function bought1()     {         var s = '<%= button2.clientid %>';         var v = document.getelementbyid(s);         v.click();     }     </script> 

but when have same thing in separate file, though function is executed - value of v remains null.

i tried simple div , did find div.

why doesn't find asp.net button?

edit

i added clientidmode="static" button. no change.

<%= button2.clientid %> server code. cannot run server code in separate javascript file.

if want access server control id separate javascript, need make clientidmode either preditable or static.

here example.

the following code. not example, hope idea.

note: make sure not have same ids when use clientidmode="static". otherwise, ids collide. example, 1 in master page , 1 in content page.

aspx

<script src="/javascript1.js"></script> <asp:button runat="server" id="button1" clientidmode="static"      text="i button" /> <div onclick="bought1()">click me</div> 

javascript file

function bought1() {     var s = 'button1';     var v = document.getelementbyid(s);     v.click(); } 

enter image description here


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -