Kentico 11 AutoPostBack control in transformation

John Jones asked on February 5, 2019 15:56

Hello,

I have this code which I have in pager layout transformation. I'm trying to trigger the event log but it seems the event does not fire. Has anyone done this before?

Thank you,

<script runat="server">
protected override void OnInit(EventArgs e) 
{
    drp.SelectedIndexChanged += drp_SelectedIndexChanged;
}

protected void drp_SelectedIndexChanged(object sender, EventArgs e)
{
    CMS.EventLog.EventLogProvider.LogInformation("TEST", "TEST", drp.SelectedValue);
}
</script>

<div class="page-filter">
<div class="page-filter__left">
    <div class="filter-item select">
        <label class="visually-hidden" for="drp">placeholder</label>
        <asp:DropDownList runat="server" ID="drp" AutoPostBack="true">
            <asp:ListItem Value="">placeholder</asp:ListItem>
            <asp:ListItem Value="1">1</asp:ListItem>
            <asp:ListItem Value="2">2</asp:ListItem>
        </asp:DropDownList>            
    </div>
</div>
<div class="filter-divider"></div>
<div class="page-filter__right">
    <div class="filter-item">
        <asp:PlaceHolder runat="server" ID="plcFirstPage"></asp:PlaceHolder>
        <asp:PlaceHolder runat="server" ID="plcPreviousPage"></asp:PlaceHolder> 
        <asp:PlaceHolder runat="server" ID="plcDirectPage"></asp:PlaceHolder>  
        <asp:PlaceHolder runat="server" ID="plcPreviousGroup"></asp:PlaceHolder>
        <asp:PlaceHolder runat="server" ID="plcPageNumbers"></asp:PlaceHolder>
        <asp:PlaceHolder runat="server" ID="plcNextGroup"></asp:PlaceHolder> 
        <asp:PlaceHolder runat="server" ID="plcNextPage"></asp:PlaceHolder>
        <asp:PlaceHolder runat="server" ID="plcLastPage"></asp:PlaceHolder>            
    </div>    
</div>    

Recent Answers


Brenden Kehren answered on February 6, 2019 15:05

Try assiging the method directly to the control vs. in code behind.

<asp:DropDownList runat="server" ID="drp" AutoPostBack="true" OnSelectedIndexChanged="drp_SelectedIndexChanged">

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on February 7, 2019 17:25

I'm not sure this is the best way to reach desired behavior. I'd implement user control with all needed logic and use it within the transformation.

Transformation is a tool to present data. Any logic should be implemented in code behind, unless this is really simple ui feature.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.