2012-03-20 68 views
1

編輯:我找到了什麼導致了這個問題,但我不知道爲什麼,我不知道如何解決它。我使用jQuery Mobile的主題來我的網站,當我刪除此行:中繼器ItemCommand在鏈接到頁面時不工作

<div data-role="page" data-theme="a"> 

我可以得到中繼器的正常工作。有誰知道我如何保持我的主題,並讓這個中繼器工作?

好吧,我有這樣一個轉發器:

<asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand" EnableViewState="true"> 
<ItemTemplate> 
    <li> 
     <asp:LinkButton ID="Button1" runat="server" Text='<%# Container.DataItem %>' CommandName="Redirect" /> 
    </li> 
</ItemTemplate> 
</asp:Repeater> 

而後面的代碼,它看起來像這樣

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) 
    { 
     if (e.CommandName == "Redirect") 
     { 
      Session["contact"] = ((LinkButton)e.CommandSource).Text; 
      Response.Redirect("Contact_Details.aspx"); 
     } 
    } 

如果我直接導​​航到該頁面(沒有鏈接到它從另一個頁面)中繼器將觸發ItemCommand。但是,如果我將登錄頁面重定向回此頁面,或者只需單擊另一頁面上的此頁面鏈接,則單擊鏈接按鈕時不會觸發itemcommand。任何線索,爲什麼這是?

編輯:此頁面的完整代碼是:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Contacts.aspx.cs" Inherits="WebApplication3.Contacts" %> 
<%@ MasterType VirtualPath = "~/Site1.Master" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 

<asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand" EnableViewState="true"> 
<HeaderTemplate> <ul data-role='listview' data-theme='c' data-inset='true'> 
    <li data-role="list-divider"><center><h1>Contacts</h1></center></li></HeaderTemplate> 
<ItemTemplate> 
    <li> 
     <asp:LinkButton ID="Button1" runat="server" Text='<%# Container.DataItem %>' CommandName="Redirect" /> 
    </li> 
</ItemTemplate> 
<FooterTemplate></ul></FooterTemplate> 
</asp:Repeater> 

</asp:Content> 

在頁面加載我連接到連接到Exchange並返回一個數組了一個Web服務。我做一個快速陣列轉換爲陣列表,然後其餘的代碼是:

//Converts the array grabbed from the webservice to an arraylist 
ArrayList testList = ArrayList.Adapter(contactsList); 


      Repeater1.DataSource = testList; 
      Repeater1.DataBind(); 

     Repeater1.ItemCommand += new RepeaterCommandEventHandler(Repeater1_ItemCommand); 
    } 
+0

頁面上必須存在基礎的javascript錯誤。你運行一個分析器來掃描正在發生的任何錯誤嗎?或者,你在PageLoad中有沒有可能會停止執行的代碼?我們需要查看代碼的其餘部分。 – msigman 2012-03-20 03:46:55

+0

編輯原帖。我在頁面上沒有任何錯誤。我的問題是爲什麼當我在瀏覽器中輸入此頁面的URL時工作,但當我的站點的另一個頁面鏈接到它或重定向到它時無法工作? – Novacane 2012-03-20 04:08:46

+0

點擊鏈接按鈕後發生回傳嗎? – PraveenVenu 2012-03-20 04:15:23

回答

1

所以我想通了這條線給我一個問題。

在我的母版頁我有:

<div data-role="page" data-theme="a"> 

這行是我的jQuery Mobile的主題。當我評論它,它打破了主題,但重複的工作。所以我查看了JQuery Mobile文檔,發現我可以將rel =「external」作爲鏈接到此頁面的鏈接的一個屬性。這將消除AJAX轉換並強制頁面在單擊時刷新。

不確定爲什麼這是一個問題,任何大師有一個想法?

相關問題