Jquery Mobile:取消回发导致页面加载错误

发布于 2024-12-05 22:30:47 字数 1644 浏览 0 评论 0原文

因此,我已经尝试让这个页面正常工作几天了,当我单击发送按钮时它会工作,但如果您尝试按 Enter 键,它只会回发到同一页面。昨天我以为我终于得到了它,所以它可以在 chrome 上运行(它在 firefox 上运行得很好,但在 chrome/safari 上崩溃了,它是一个 iPhone 的应用程序)。但是,尽管我最终得到了它,因此它会更改页面,但它现在显示错误。我将原因缩小到在发送我想要的回发之前调用的回发,然后将其取消。我认为取消的回发是空白的,因为我遇到的问题是页面会执行空白回发。

来“修复”该问题

javascript:if (event.keyCode == 13) __doPostBack('" & btnSearch.UniqueID & "','') 

我通过添加到 txtSearch 的 onKeyPress 。 asp:LinkBut​​ton 和 asp:TextBox 的结束 html(包含在 asp:Panel 中,位于表单内的母版页的 asp:Content 中,可能相关也可能不相关)是

<input name="ctl00$contentMain$txtSearch" id="contentMain_txtSearch" type="text" data-type="search" onkeypress="javascript:if (event.keyCode == 13) __doPostBack('ctl00$contentMain$btnSearchByIDName','')" class="...">

<a id="contentMain_btnSearch" class="..." data-role="button" onclientclick="return false;" href="javascript:__doPostBack('ctl00$contentMain$btnSearch','')" data-theme="c"><span class="..."><span class="...">Search</span></span></a>

有一个 on 按钮点击事件在后面的代码中。

这是帖子的标题,回复,其他一切都是空的。

Accept:text/html, */*; q=0.01
Content-Type:application/x-www-form-urlencoded
Origin:Local.Website
Referer:Local.Website/EmployeePhoneList/PhoneList.aspx
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1
X-Requested-With:XMLHttpRequest

任何人都知道如何弄清楚为什么要进行两次回发?或者我如何确定是什么原因造成的?感谢您的任何帮助。

更新:进一步查看响应,btnSearch 是错误和正确回发的来源。另外,还没有工作的东西,AutoPostBack =“false”,CauseValidation =“false”,ViewStateMode =“Disabled”和UseSubmitBehavior =“false”。

So, I've been trying to get this page working for a couple of days now, when I clicked the send button it would work, but if you tried to hit enter it would just do a postback to the same page. Yesterday I thought I finally got it so it would work on chrome (it has been working just fine on firefox, but breaking on chrome/safari and it is an app for the iphone). But, even though I finally got it so it would change pages, it is now displaying an error. I narrowed down the cause to a postback that is being called right before the postback I want is being sent which is then cancelled. I assume the cancelled postback is blank because the problem I was having was the page would do a blank postback.

I 'fixed' the problem by adding

javascript:if (event.keyCode == 13) __doPostBack('" & btnSearch.UniqueID & "','') 

to the onKeyPress for txtSearch. The ending html for the asp:LinkButton and asp:TextBox (which is enclosed in an asp:Panel, inside an asp:Content for a master page which is inside a form, may or may not be relevant) is

<input name="ctl00$contentMain$txtSearch" id="contentMain_txtSearch" type="text" data-type="search" onkeypress="javascript:if (event.keyCode == 13) __doPostBack('ctl00$contentMain$btnSearchByIDName','')" class="...">

<a id="contentMain_btnSearch" class="..." data-role="button" onclientclick="return false;" href="javascript:__doPostBack('ctl00$contentMain$btnSearch','')" data-theme="c"><span class="..."><span class="...">Search</span></span></a>

There is an on button click event in the code behind.

This is the header from the post, the response and everything else is empty.

Accept:text/html, */*; q=0.01
Content-Type:application/x-www-form-urlencoded
Origin:Local.Website
Referer:Local.Website/EmployeePhoneList/PhoneList.aspx
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1
X-Requested-With:XMLHttpRequest

Anyone have any ideas how to figure out why it is doing two postbacks? Or how I could determine what is causing it? Thanks for any help.

Update: Looking further into the response, btnSearch is the origin for both the incorrect and correct postbacks. Also, things that HAVE NOT worked, AutoPostBack="false", CauseValidation="false", ViewStateMode="Disabled" and UseSubmitBehavior="false".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尴尬癌患者 2024-12-12 22:30:47

您是否尝试过禁用 jQuery Mobile 的 Ajax 导航?这是我在 MVC 项目中的做法,在 WebForms 中应该类似:

<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")"></script>
<script type="text/javascript">
   $(document).bind("mobileinit", function() {
       $.mobile.ajaxEnabled = false;
   });
</script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.mobile-1.0b2.min.js")"></script>

Have you tried disabling jQuery Mobile's Ajax navigation? Here's how I did it in an MVC project, should be similar in WebForms:

<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")"></script>
<script type="text/javascript">
   $(document).bind("mobileinit", function() {
       $.mobile.ajaxEnabled = false;
   });
</script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.mobile-1.0b2.min.js")"></script>
半衬遮猫 2024-12-12 22:30:47

在修复另一个页面上看似不相关的问题时,我们意外地修复了该问题。事实证明,即使使用 ajaxEnabled = false,有时也需要将 data-ajax="false" 以母版页的形式放置,以使 ASP.NET 代码能够在 JQuery 移动设备上正常工作。要么是 rc1 解决了这个问题,我不确定,现在我不再关心了。

While fixing an seemingly unrelated problem on another page we accidentally fixed the problem. Turns out even with ajaxEnabled = false, you sometimes need to put data-ajax="false" in the form of the masterpage to make asp.net code work correctly with JQuery mobile. Either that or rc1 fixed the problem, I don't know for sure and at this point I don't really care anymore.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文