为什么将我的JQuery按钮放置在母版页上后立即回发? [英] Why is my JQuery button posting back immediately when placed in a masterpage?

查看:98
本文介绍了为什么将我的JQuery按钮放置在母版页上后立即回发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经为此苦苦挣扎了一段时间,所以希望有人能够帮助我.我基本上已经复制了此页面的源代码: http://jqueryui.com/demos/dialog/#modal-form 分为两个不同的aspx页,一个是标准页,另一个是使用母版页. 正常"页面第一页工作正常,但在母版页上,此处的按钮:

Hi,

I have been struggling with this for a while now, so was hoping someone might be able to help me out. I have basically copied the source of this page: http://jqueryui.com/demos/dialog/#modal-form into two different aspx pages, one standard one, and one that uses a masterpage. The "normal" page one works perfectly, but on the masterpage, the button here:

<button id="create-user">Create new user</button>


单击后立即回发,这显然意味着模态对话框永远不会出现(或在页面重新发发之前短暂出现).我一生都无法弄清楚为什么母版页会影响到这一点.两个页面具有完全相同的代码,除了母版页中的内容外,没有任何多余的内容(并且在代码背后也没有任何内容),当然其中包括以下内容:


immediately posts back when you click it, meaning obviously that the modal dialog never appears (or appears briefly before the page reposts). I cannot for the life of me work out why the masterpage would affect this. Both pages have the exact same code, with nothing extra (and nothing whatsoever in the code-behind), except what''s in the masterpage, which of course includes this:

<script type="text/javascript" src="/JS/jquery-1.4.2.min.js"></script>
   <script type="text/javascript" src="/JS/jquery-ui-1.8.4.custom.min.js"></script>



我尝试更改此内容:



I tried changing this:

$(''#create-user'')
            .button()
            .click(function () {
                $(''#dialog-form'').dialog(''open'');
            });




为此(考虑到母版页对clientID的重命名):




to this (to take into account the renaming of clientIDs by the masterpage):

$(''#ctl00_ContentPlaceHolder1_create-user'')
            .button()
            .click(function () {
                $(''#dialog-form'').dialog(''open'');
            });




但无济于事,每当我单击该按钮时,该按钮仍会立即回发.我知道我可以使用return:false;停止此操作,但最终我想从中运行eventhandler代码...

有人知道为什么会这样吗?我想在项目中使用JQuery(这是我的新手),但是如果我什至无法获得演示的复制/粘贴功能,它就不会太好.....




but to no avail, the button still posts back instantly whenever I click it. I know I can stop this with return:false; but I eventually want to run eventhandler code from it...

Does anyone know why this is happening? I want to use JQuery (which I''m new to) in my project, but if I cannot even get a copy/paste of the demo to work, it doesn''t bode too well....

推荐答案

(``#create-user'') .按钮() .click(function(){
(''#create-user'') .button() .click(function () {


(``#dialog-form'').dialog(``open''); });
(''#dialog-form'').dialog(''open''); });




为此(考虑到母版页对clientID的重命名):




to this (to take into account the renaming of clientIDs by the masterpage):


(``#ctl00_ContentPlaceHolder1_create-user'') .按钮() .click(function(){
(''#ctl00_ContentPlaceHolder1_create-user'') .button() .click(function () {


这篇关于为什么将我的JQuery按钮放置在母版页上后立即回发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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