Asp repeater & LinkButton

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Kirk

    Asp repeater & LinkButton

    Hi

    are there any "gotchas" with using an asp:repeater that means that the
    "onclick" method of a LinkButton created in the repaeter does not fire?

    I at least cannot get it to work. I have a webpage where the user can enter
    some search criteria (via dropdowns and textboxes) and then perform a search
    and have results presented. The results list includes linkbuttons which the
    user can click on to obtain more detailed results.

    Here is some example code if anyone would be kind enough to offer advice.

    On html/asp:

    <asp:repeater id="ResultsRepe ater" onitemdatabound ="Item_DataBoun d"
    Runat="server">
    <HeaderTemplate >
    <table>
    <tr>
    <th>Name</th>
    <th>Code</th>
    </tr>
    </HeaderTemplate>
    <ItemTemplate >
    <tr>
    <td><%# ((DataRow)Conta iner.DataItem). Name %></td>
    <td>
    <asp:LinkButt on id="MyButton"
    OnClick="MyButt onMenuItem_Clic k" Runat="server" text="<%#
    ((DataRow)Conta iner.DataItem). Code %>" />
    </td>
    </tr>
    </ItemTemplate>
    <FooterTemplate >
    </table>
    </FooterTemplate>
    </asp:repeater>


    In code behind:

    private void Page_Load(objec t sender, System.EventArg s e)
    {
    log.Info("Page_ Load");

    string detail = Request.Params["detail"];

    if (!IsPostBack)
    {
    log.Info("Page_ Load !IsPostBack");

    // Populates fields for supplying search criteria:
    PopulateSearchD ropDowns();
    }
    else
    {
    log.Info("Page_ Load IsPostBack");
    }

    log.Info("PortT oPort Page_Load END");
    }

    // Never gets called
    public void MyButtonMenuIte m_Click(object sender, EventArgs e)
    {
    log.Info("MyBut tonMenuItem_Cli ck");
    LinkButton btn = (LinkButton)sen der;

    // Supposed to do stuff to handle the linkbutton click...
    }

    // Click-handler for the "send" button, which generates the data for the
    repeater.
    private void SendQueryButton _Click(object sender, System.EventArg s e)
    {
    log.Info("SendB utton_Click ...");

    // ... data handing/validation... call the database "Search" method to
    get the data:
    ArrayList results = Search();
    ResultsRepeater .DataSource = results;
    ResultsRepeater .DataBind();

    log.Info("END SendButton_Clic k ...");
    }


  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: Asp repeater &amp; LinkButton

    Hi,

    No really, it should work fine.

    What does Item_DataBound? the problem may lay there.

    cheers,

    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation



    "Peter Kirk" <pk@alpha-solutions.dk> wrote in message
    news:Og2rk2R4FH A.476@TK2MSFTNG P15.phx.gbl...[color=blue]
    > Hi
    >
    > are there any "gotchas" with using an asp:repeater that means that the
    > "onclick" method of a LinkButton created in the repaeter does not fire?
    >
    > I at least cannot get it to work. I have a webpage where the user can
    > enter some search criteria (via dropdowns and textboxes) and then perform
    > a search and have results presented. The results list includes linkbuttons
    > which the user can click on to obtain more detailed results.
    >
    > Here is some example code if anyone would be kind enough to offer advice.
    >
    > On html/asp:
    >
    > <asp:repeater id="ResultsRepe ater" onitemdatabound ="Item_DataBoun d"
    > Runat="server">
    > <HeaderTemplate >
    > <table>
    > <tr>
    > <th>Name</th>
    > <th>Code</th>
    > </tr>
    > </HeaderTemplate>
    > <ItemTemplate >
    > <tr>
    > <td><%# ((DataRow)Conta iner.DataItem). Name %></td>
    > <td>
    > <asp:LinkButt on id="MyButton"
    > OnClick="MyButt onMenuItem_Clic k" Runat="server" text="<%#
    > ((DataRow)Conta iner.DataItem). Code %>" />
    > </td>
    > </tr>
    > </ItemTemplate>
    > <FooterTemplate >
    > </table>
    > </FooterTemplate>
    > </asp:repeater>
    >
    >
    > In code behind:
    >
    > private void Page_Load(objec t sender, System.EventArg s e)
    > {
    > log.Info("Page_ Load");
    >
    > string detail = Request.Params["detail"];
    >
    > if (!IsPostBack)
    > {
    > log.Info("Page_ Load !IsPostBack");
    >
    > // Populates fields for supplying search criteria:
    > PopulateSearchD ropDowns();
    > }
    > else
    > {
    > log.Info("Page_ Load IsPostBack");
    > }
    >
    > log.Info("PortT oPort Page_Load END");
    > }
    >
    > // Never gets called
    > public void MyButtonMenuIte m_Click(object sender, EventArgs e)
    > {
    > log.Info("MyBut tonMenuItem_Cli ck");
    > LinkButton btn = (LinkButton)sen der;
    >
    > // Supposed to do stuff to handle the linkbutton click...
    > }
    >
    > // Click-handler for the "send" button, which generates the data for the
    > repeater.
    > private void SendQueryButton _Click(object sender, System.EventArg s e)
    > {
    > log.Info("SendB utton_Click ...");
    >
    > // ... data handing/validation... call the database "Search" method to
    > get the data:
    > ArrayList results = Search();
    > ResultsRepeater .DataSource = results;
    > ResultsRepeater .DataBind();
    >
    > log.Info("END SendButton_Clic k ...");
    > }
    >
    >[/color]


    Comment

    • Peter Kirk

      #3
      Re: Asp repeater &amp; LinkButton

      "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > skrev
      i en meddelelse news:OQRu5dU4FH A.1148@tk2msftn gp13.phx.gbl...[color=blue]
      > Hi,
      >
      > No really, it should work fine.
      >
      > What does Item_DataBound? the problem may lay there.[/color]

      Hi

      thanks for the reply. After more experimentation it does seem that the code
      works as I would have expected it to, if I run it as a "stand-alone"
      webpage. Unfortunately the ascx I am making is running inside a "container"
      (a CMS) which appears to swallow these click events. I will need to
      investigate further.

      Peter


      Comment

      Working...