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

Access a server-side dynamic added multipage on client-side with javascript

1 Answer 79 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Thorsten
Top achievements
Rank 1
Thorsten asked on 01 Feb 2012, 04:33 PM
Hello,

i have to access a multipage that was added dynamically on server-side on the client-side with javascript to make it visible and set the selected index.
For example, a multipage that was added at designtime i access like this:
function selectNews() {
                    var mV = $find("<%= radThumbs.ClientID %>");
                    mV.set_selectedIndex(1);
                }

This works very well. But now i have to access a dynamically added multipage. All my attempts are without luck.
In codebehind i set a unique id to each dynamic added multipage. In html-output that is generated the multipages are stored as div-tags with a id that is equal to that, that i set in codebehind on server-side.

so far i tried different ways to get the control on client side.

Attempt #1:
alert('item.children[i].innerHTML.replace(/\s/g, "")');
var test = $find(item.children[i].innerHTML.replace(/\s/g, ""));
 test.set_selectedIndex(1);
Attempt #2:
alert('item.children[i].innerHTML.replace(/\s/g, "")');
var test = document.getElementById(item.children[i].innerHTML.replace(/\s/g, ""));
test.set_selectedIndex(1);
 
 
In all attempts the alertbox shows the correct id.
But ever i try to set the selected index, a error occurs and tells me, that the element doesn't contain such a method and so on.

Thanks for your assistence...

Thorsten

1 Answer, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 03 Feb 2012, 03:45 PM
Hi Thorsten,

I created a simple page that you could test where I set the index of a dynamically created pageview using the client-side set_selectedIndex() method:

<script type="text/javascript">
        function pageLoad() {
            var multiPage = $find("<%=RadMultiPage1.ClientID %>");
            multiPage.set_selectedIndex(1);
//          var pageview1 = multiPage.findPageViewByID("Corporate1");
//          pageview1.set_selected(true);
        }
    </script>
    <div>
        <telerik:RadTabStrip ID="RadTabStrip1" SelectedIndex="0" runat="server" MultiPageID="RadMultiPage1">
        </telerik:RadTabStrip>
        <telerik:RadMultiPage ID="RadMultiPage1" runat="server">
        </telerik:RadMultiPage>
    </div>

code behind:
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
 
            RadTab tab = new RadTab();
            tab.Text = "Corporate";
            RadTabStrip1.Tabs.Add(tab);
            Label lbl1 = new Label();
            lbl1.Text = "label1";
            RadPageView pageView = new RadPageView();
            pageView.ID = "Corporate";
            RadMultiPage1.PageViews.Add(pageView);
            pageView.Controls.Add(lbl1);
 
 
            RadTab tab1 = new RadTab();
            tab1.Text = "Corporate1";
            RadTabStrip1.Tabs.Add(tab1);
            Label lbl11 = new Label();
            lbl11.Text = "label11";
            RadPageView pageView1 = new RadPageView();
            pageView1.ID = "Corporate1";
            RadMultiPage1.PageViews.Add(pageView1);
            pageView1.Controls.Add(lbl11);
        }
    }

Kind regards,
Kate
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
TabStrip
Asked by
Thorsten
Top achievements
Rank 1
Answers by
Kate
Telerik team
Share this question
or