1

編集: 問題の原因を突き止めましたが、その理由と修正方法がわかりません。JQuery Mobile を使用してサイトのテーマを設定していますが、次の行を削除すると:

<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 を起動します。しかし、ログイン ページをこのページにリダイレクトしたり、別のページからこのページへのリンクをクリックしたりすると、リンク ボタンをクリックしても item コマンドがトリガーされません。これがなぜなのかについての手がかりはありますか?

編集: このページの完全なコードは次のとおりです。

<%@ 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>

ページの読み込みでは、交換に接続して配列を返す Web サービスに接続します。配列をarraylistにすばやく変換すると、残りのコードは次のようになります。

//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);
    }
4

1 に答える 1

1

それで、問題を引き起こしている行を見つけました。

私のマスターページには次のものがありました:

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

この行は、私の JQuery Mobile テーマ用です。コメントアウトしたところ、テーマが壊れましたが、リピーターは機能しました。そこで、JQuery Mobile のドキュメントを調べたところ、このページにリンクするリンクの属性として rel="external" を設定できることがわかりました。これにより、AJAX トランジションが削除され、クリック時にページが強制的に更新されます。

なぜこれが問題だったのか正確にはわかりません。

于 2012-03-22T05:38:42.013 に答える