return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - how to do a getElementById on an ASP.NET control - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to do a getElementById on an ASP.NET control - Stack Overflow

programmeradmin4浏览0评论

I have an element on my page.

<asp:Button ID="buttonToFind" runat="server" OnClick="SomeProcess" />

In javascript I'm trying to find this control using:

document.getElementById("buttonToFind");

However it can't seem to find the control. My understanding is that the asp:Button gets changed to an input element? This input has a new ID that contains the original ID but with a lot of extra characters therefore I can't find the original ID on the page?

Is this correct?

Also given this how would I go about specifying the correct ID to search for?

I have an element on my page.

<asp:Button ID="buttonToFind" runat="server" OnClick="SomeProcess" />

In javascript I'm trying to find this control using:

document.getElementById("buttonToFind");

However it can't seem to find the control. My understanding is that the asp:Button gets changed to an input element? This input has a new ID that contains the original ID but with a lot of extra characters therefore I can't find the original ID on the page?

Is this correct?

Also given this how would I go about specifying the correct ID to search for?

Share Improve this question edited Dec 20, 2010 at 20:40 BigJim asked Nov 10, 2010 at 3:16 BigJimBigJim 4111 gold badge6 silver badges20 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

You need the ClientID property of the control. In ASP.NET 4 you can also set the ClientIDMode to Static. Source

Your understanding is correct.

This will work if the JS is on the ASPX/ASCX markup:

document.getElementById('<%= buttonToFind.ClientID %>');

If the JS is external, you'll need to do extra work (e.g use a literal to hold the ID's, or register a script).

Any server control will be gave new client side Id so yuo can use the ClientId of any control you wana pass to Javascript :) so

document.getElementById('<%= buttonToFind.ClientID %>'); 

should be your answer

You need to get the server control's client id:

document.getElementById("<%=buttonToFind.ClientID%>");
发布评论

评论列表(0)

  1. 暂无评论