PDA

View Full Version : [CLOSED] How to register items on page load from code behind when using a masterpage



tMp
Jan 18, 2014, 9:50 AM
Hi

I run into some trouble when adding items on page load while using a master page. I found this post (http://forums.ext.net/showthread.php?1367-Loading-a-UserControl-(ascx)-to-a-page) about Ext.Net v1.x but I wasn't able to find the equivalent in v2.x. How do I address this BodyControls issue in my example?

Thank you very muche.

MasterPage:

<%@ Master Language="C#" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<ext:ResourceManager ID="ResourceManager" runat="server" Locale="de-CH"></ext:ResourceManager>
<title></title>
<asp:ContentPlaceHolder id="CPH_HEAD" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="CPH_BODY" runat="server">

</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>


example

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
ComboBox cbbTest = new ComboBox
{
ID = "cbbID",
FieldLabel = "Year",
Items = { new Ext.Net.ListItem("2014", "2014") },
Listeners = { Select = { Handler = "App.direct.onSelect()" } }
};
container.Items.Add(cbbTest); // <<--- not working like this
}
}

[DirectMethod]
public void onSelect()
{
X.Msg.Alert("Selected Year", X.GetCmp<ComboBox>("cbbID").SelectedItem.Value).Show();
}

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="CPH_HEAD" Runat="Server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CPH_BODY" Runat="Server">

<ext:Container ID="container" runat="server" Padding="5"></ext:Container>

</asp:Content>

Daniil
Jan 20, 2014, 4:18 AM
Hi @tMp,

Could you, please, clarify what exactly doesn't work in your sample?

The ComboBox is rendered for me. Not for you?

If you are about this

X.GetCmp<ComboBox>("cbbID").SelectedItem.Value
returns nothing, then you should replace it with

X.GetCmp<ComboBox>("CPH_BODY_cbbID").SelectedItem.Value

By default, a control's client id is combined with INamingContainers' ids.

tMp
Jan 20, 2014, 6:50 AM
@Daniil

Thank you, I was looking for the last part, which solved my problem.