This is a migrated thread and some comments may be shown as answers.

problem with dynamic button on dynamic pageview

1 Answer 30 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
paul
Top achievements
Rank 1
paul asked on 12 Aug 2010, 04:56 AM
couldn't find a more appropriate forum category...

button click seems to drop out when you add a dynically create button to a dynmically created pageview.
works ok if you add a dynamic button to an existing pageview.
is this an issue or am i doing it wrong?
code snippets follow...

thanks,
paul

p.s. if i add the button dynamically to the specific pageview "PV1" then the click works



        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["counter"] != null)
            { counter = (int)Session["counter"]; }

            Telerik.Web.UI.RadPageView newPageView = new Telerik.Web.UI.RadPageView();
            newPageView.ID = "pv_" + counter.ToString();
            newPageView.Visible = true;
            MP1.PageViews.Add(newPageView);
            MP1.SelectedIndex = MP1.FindPageViewByID(newPageView.ID).Index;

            Telerik.Web.UI.RadTab newTab = new Telerik.Web.UI.RadTab();
            newTab.Text = newPageView.ID;
            newTab.Visible = true;
            TS1.Tabs.Add(newTab);
            TS1.SelectedIndex = TS1.FindTabByText(newTab.Text).Index;

            System.Web.UI.WebControls.Button newButton = new System.Web.UI.WebControls.Button();
            newButton.ID = "btn_" + counter.ToString();
            newButton.Text = "Close Image";
            newButton.Click += new EventHandler(btnRemoveFromList_Click);
            newPageView.Controls.Add(newButton);

            counter++;
            Session["counter"] = counter;
    }


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestCtrl.ascx.cs" Inherits="WebApplication2.TestCtrl" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<link rel="Stylesheet" type="text/css" href="~/Styles/SiteX.css" id="style" runat="server" visible="false" />
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>

<telerik:RadTabStrip ID="TS1" runat="server" SelectedIndex="0"
  MultiPageID="MP1" Skin="Simple">
    <Tabs>
            <telerik:RadTab runat="server" Text="Search">
                </telerik:RadTab>
    </Tabs>
</telerik:RadTabStrip>

<telerik:RadMultiPage ID="MP1" Runat="server" SelectedIndex="0"
            Width="100%" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px">
    <telerik:RadPageView ID="PV1" runat="server">
        </telerik:RadPageView>
</telerik:RadMultiPage>










1 Answer, 1 is accepted

Sort by
0
paul
Top achievements
Rank 1
answered on 12 Aug 2010, 05:21 AM
ok, worked it out.

needed to add the button within a PageViewCreated and it all works swimmingly...

thanks
paul

        protected void Page_Load(object sender, EventArgs e)
        {

            int counter = 0;
            if (Session["counter"] != null)
            { counter = (int)Session["counter"]; }

            Telerik.Web.UI.RadPageView newPageView = new Telerik.Web.UI.RadPageView();
            newPageView.ID = "pv_" + counter.ToString();
            newPageView.Visible = true;
            MP1.PageViews.Add(newPageView);
            MP1.SelectedIndex = MP1.FindPageViewByID(newPageView.ID).Index;

            Telerik.Web.UI.RadTab newTab = new Telerik.Web.UI.RadTab();
            newTab.Text = newPageView.ID;
            newTab.Visible = true;
            TS1.Tabs.Add(newTab);
            TS1.SelectedIndex = TS1.FindTabByText(newTab.Text).Index;

            counter++;
            Session["counter"] = counter;
        }


        protected void MP1_PageViewCreated(object sender, Telerik.Web.UI.RadMultiPageEventArgs e)
        {
            Telerik.Web.UI.RadPageView tempPageView = e.PageView;

            System.Web.UI.WebControls.Button newButton = new System.Web.UI.WebControls.Button();
            newButton.ID = "btn_" + tempPageView.ID.ToString();
            newButton.Text = "Close Image " + newButton.ID;
            newButton.Click += new EventHandler(btnRemoveFromList_Click);
            tempPageView.Controls.Add(newButton);
        }
Tags
General Discussions
Asked by
paul
Top achievements
Rank 1
Answers by
paul
Top achievements
Rank 1
Share this question
or