在哪里可以使用asp.net的用户控件,当我把JavaScript的? [英] Where do I put JavaScript when using an asp.net user control?

查看:130
本文介绍了在哪里可以使用asp.net的用户控件,当我把JavaScript的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个详细信息链接的用户控件。当点击该链接,我想一个div出现这给了用户更多的信息。

I have a user control with a "More Info" link. When clicking that link, I want a div to appear which gives the user more information.

我在哪里可以把JavaScript的?它不会出现在我的用户控件的顶部放置时工作。如何当您使用的用户控件您处理JavaScript和jQuery?我已经包括在我的母版页jQuery库。我经常asp.net页面的JavaScript和那些工作。

Where do I put the JavaScript? It doesn't appear to work when placing at the top of my user control. How do you handle JavaScript and jQuery when you are using a user control? I have the jQuery library included in my master page. My regular asp.net pages have JavaScript and those work.

编辑:看来,做客户端编码用户控件的方式是通过服务器端,类似于asp.net服务器控件如何工作做输出的脚本。令人失望的是,jQuery是如此真棒,但所有的例子都严格嵌入到HTML / aspx页面上。是否有一个资源在那里的jQuery用asp.net,我还没有发现?

It appears that the way to do client side coding in a user control is to do output a script via server side, similar to how the asp.net server controls work. What is disappointing is that jQuery is so awesome but all the examples are strictly embedded on the html/aspx page. Is there a resource out there for jQuery with asp.net that I haven't found yet?

推荐答案

使用 ClientScriptManager .RegisterStartUpScript 的页面在服务器端的端设置脚本。或使用就绪事件 JQuery的的保证DOM被加载,然后绑定你的客户端事件您的链接。

Use ClientScriptManager.RegisterStartUpScript to set your scripts at the end of the page at server side. Or use ready event of the JQuery ensure the dom is loaded, and then bind your client side events to your link.

的RegisterStartupScript,在页面的最后注册脚本,让你的脚本加载页面的所有元素后加载。

RegisterStartupScript, registers your scripts at the end of the page, so your script loaded after all the elements of the page loaded.

另外一种选择是使用的jQuery ready事件,它可以帮助你等待DOM的所有元素加载。您可以实现内联或服务器端您准备的功能。

One other option is to use ready event of the JQuery, it helps you to wait all elements of DOM loaded. You can implement your ready function at inline or server side.

这里的关键点是等待DOM元素负载。

The key point here is to wait for the DOM elements load.

这篇关于在哪里可以使用asp.net的用户控件,当我把JavaScript的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆