开发者

Is jQuery runs only client side controll and gives error when we add runat=server

I am working on a Portfolio project in which I am displaying Images in a Div "Book" . For giveng it an effect am using a jQuery that set the Div's size to a fixed size(500*700). Everything was going fine.

Now I need to controll the size of the division at runtime(new requirement). as soon as i add runat="server" to div jQuery starts to raise an error "Book is null or not an object" at bold position.

Book.appendChild(B_LI);
B_RI = document.createElement("img"); **Bo开发者_如何学Gook.appendChild(B_RI);**
B_MI = document.createElement("img"); Book.appendChild(B_MI);

I am not much familier with jQuery. Is jQuery runs only client side controll and gives error when we add runat=server.

Thanks

Suren


When you add runat=server, ASP.NET mangles the ID of the control.

You need to retrieve the ClientID and then refer it as the normal ID in your JQuery code.

Here is the example, where user_options is the object of the HTML control to which you have added runat attribute.

<script type="text/javascript">
$(function() { if (user) { $("#<%= user_options.ClientID %>").hide();});
</script>

jquery and html elements that run at server


I guess the problem is that ASP.NET generates ID s for controls marked as runat=server depending in which container is the control.

Change in JQuery/JavaScript scripts to use <%= Book.ClientID %> instead of 'Book' when accessing to that control.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜