CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 1/11/2008 4:05:37 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 3 Views: 173 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
4 Items, 1 Pages 1 |< << Go >> >|
scarabee
Asp.Net User
MultiView: How to add View items programmatically1/11/2008 4:05:37 PM

0/0

I have tried to add View items to my MultiView control, but I only got the error below. I added the my code in Page_Load event. But when I move my code to Page_PreInit I can't find my controls. I added a MultiView control in the design page. How can I reference this now. It seem unreachable from Page_PreInit. Some tips to help me on my way?

ActiveViewIndex is being set to '1'.  It must be smaller than the current number of View controls '1'. For dynamically added views, make sure they are added before or in Page_PreInit event.
Parameter name: value

 Regards, Sigurd

moises.dl
Asp.Net User
Re: MultiView: How to add View items programmatically1/11/2008 4:59:31 PM

0/0

i dont understand what youre trying to do, are you trying to add controls to your multiview view are you trying to add views to your multiview or are you trying to access either one of those?


Thanks A Bunch
scarabee
Asp.Net User
Re: MultiView: How to add View items programmatically1/12/2008 5:13:38 PM

0/0

OK, I shall try to explain better what I'm trying to accomplish.

I'm trying to make a admin page for administrating my articles. And I want this admin page to be multilingual so I can have an English and a Norwegina version of each article. But I want the user to dynamically add or remove availabel languages for the web site, thats the reason I want to create it programmatically.

What I want is to add View controls dynamically to my MultiView object. The number of Views I'll get from a database table containing the active languages. I tried to solve this but I got the below error. Anyone got similar code? Or can give me some tips how to solve this? Or is it better to create all controls programmatically in the code behind file?

I only get the select box to show on the page. And when I select the other View frm the select box I get the error text below.

 

ActiveViewIndex is being set to '0'.  It must be smaller than the current number of View controls '0'. For dynamically added views, make sure they are added before or in Page_PreInit event.
Parameter name: value
 

------------------------------- design ----------------------------------
    <form id="form1" runat="server">
         <asp:ListBox ID="SelectViewListBox" AutoPostBack="True" Rows="1" SelectionMode="Single" OnSelectedIndexChanged="Index_Changed" runat="Server">
        </asp:ListBox>

        <hr />

        <asp:MultiView ID="MultiView1" runat="Server">
        </asp:MultiView>
    </form>

------------------------------- C# ----------------------------------
    protected void Page_Load(object sender, EventArgs e) {
        if (!Page.IsPostBack) {
            SelectViewListBox.Items.Add(new ListItem("ViewOne", "0"));
            SelectViewListBox.Items.Add(new ListItem("ViewTwo", "1"));
            SelectViewListBox.SelectedValue = "1";

            // View one
            Label lblOne = new Label();
            lblOne.Text = "View one";
            View myViewOne = new View();
            myViewOne.Controls.Add(lblOne);
            MultiView1.Views.Add(myViewOne);

            // View two
            Label lblTwo = new Label();
            lblTwo.Text = "View two";
            View myViewTwo = new View();
            myViewTwo.Controls.Add(lblTwo);
            MultiView1.Views.Add(myViewTwo);

            MultiView1.ActiveViewIndex = 0;
        }
    }

    protected void Index_Changed(Object Sender, EventArgs e) {
        MultiView1.ActiveViewIndex = int.Parse(SelectViewListBox.SelectedValue);
    }

 Regards, Sigurd
 

Amanda Wang - M
Asp.Net User
Re: MultiView: How to add View items programmatically1/14/2008 8:03:49 AM

0/0

Hi,

You can try to add the View items programmatically in the MultiView's Load event, below is my test code, it works fine on local machine:

 protected void MultiView1_Load(object sender, EventArgs e)
    {
        Label lbl = new Label();
        lbl.Text = "Hello!";

        View view = new View();
        view.Controls.Add(lbl);

        this.MultiView1.Views.Add(view);
        this.MultiView1.ActiveViewIndex = 2;
    }

Hope it helps.


Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Yours sincerely,
Amanda Wang
Microsoft Online Community Support
4 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Pro ASP.NET 2.0 in VB 2005: From Professional to Expert Authors: Laurence Moroney, Matthew MacDonald, Pages: 1253, Published: 2006
Pro ASP.NET 3.5 in C# 2008 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1498, Published: 2007
Pro ASP.NET 2.0 in C# 2005 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1255, Published: 2005
Pro ASP.NET 2.0 in C# 2005: Create Next-generation Web Applications with the Latest Version of Microsoft's Revolutionary Technology Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1426, Published: 2006
Beginning ASP.NET 3.5 in VB 9.0: From Novice to Professional Authors: Matthew MacDonald, Pages: 1149, Published: 2007
Beginning ASP.NET 3.5 in C# 2008: From Novice to Professional Authors: Matthew MacDonald, Pages: 954, Published: 2007
ASP.NET 2.0: A Developer's Notebook Authors: Wei Meng Lee, Pages: 326, Published: 2005
Beginning Visual Web Developer 2005 Express: From Novice to Professional Authors: Paul Sarknas, Pages: 334, Published: 2005
Beginning ASP.NET 2.0 in VB 2005: From Novice to Professional Authors: Matthew MacDonald, Pages: 1063, Published: 2006
Pro Asp.net 3.5 in Vb 2008: Includes Silverlight 2 and the Ado.net Entity Framework Authors: Matthew MacDonald, Mario Szpuszta, Vidya Vrat Agarwal, Pages: 1200, Published: 2008

Web:
MultiView: How to add View items programmatically - ASP.NET Forums You can try to add the View items programmatically in the MultiView's Load event , below is my test code, it works fine on local machine: ...
Problems adding View Controls to a Multiview programmatically ... I need to add Controls to a web form page programmatically (labels, textboxes, ect. ... Then I create a view and add it to multiview control and so add controls to each view. ..... Page 1 of 1 (8 items) ...
MultiView.Views Property (System.Web.UI.WebControls) The following example demonstrates how to programmatically add View controls to a MultiView control. After each View control is created, the MultiView. ...
Visual Studio .NET I can add View dynamically to Multiview Control May 21, 2008 ... A MultiView was added to the page declaratively. ' Now add the View control programmatically. If SelectViewListBox.SelectedIndex >= 0 Then ...
MultiView using Menu Control in ASP.NET 3.5 Oct 2, 2008 ... You can define the active view declaratively or programmatically. ... between View controls within a MultiView control, you can add a ...
How to: Add MultiView Web Server Controls to a Web Forms Page Add elements as child elements of the MultiView control. ... If you do not include navigation buttons, add code to programmatically set the ...
Programmatically Assigning CreateUserStep.ContentTemplate Programmatically Assigning CreateUserStep.ContentTemplate ... Add( register ); / / A view in a MultiView control ...
Using the MultiView and Wizard Controls in ASP.NET 2.0 | O'Reilly ... Mar 21, 2006 ... NET 2.0) controls, which you can then programmatically display. ... Drag and drop two more View controls onto the MultiView control. ...
Using the MultiView control in ASP.NET 2.0 - .Net Articles & Samples Feb 19, 2006 ... Now in each View control you can add a control and some event of it .... must set this property either as the attribute or programmatically. ...
ASP.NET MultiView Navigation – extending the View Control Nov 8, 2006 ... NET View controls nested inside a MultiView. I was looking for an easy way to navigate ... 3: DropDownList1.Items.Add(lItems.FriendlyName) ...




Search This Site:










load xml file and read xml file

master pages - contentplaceholder control size in visual studio 2005 design mode

loginview - how do i access controls from javascript?

context menu in treeview

multiple sitemap file issue

prevent postback on expanding/collapsing treeviw

accessing properties in master pages when defined at run time

accessing masterpage controls from content

how do i properly use the menu control with xml?

themes are not working properly

space abov

page dependency matrix + objects

menu root node problem

when will the treeview get updated. selected node

menu items and site map

confused about linking custom sitemapprovider into site map hierarchy.

expand

asp templates

dynamically changing themes for different users

passing value via menuitem

asp.net menu

another menu/sitemap question

sitemapresolve event not firing on iis

a very simple vertical list of links using sitemap

can masterpage find out which page is loaded in a content place holder

treeview not refreshing on autopostback

templates for asp.net with support for masterpages?

multiple forms

query regarding menu control in master page

using javascript in master pages and content pages

  Privacy | Contact Us
All Times Are GMT