StaticItemTemplate is not applied on postback Options

Discussion in 'ASP .Net Web Controls' started by John123, Oct 30, 2007.

  1. John123

    John123 Guest

    Hi all,

    I am having a strange problem when using the ASP.NET (2.0) menu
    control.
    I have a menu control that gets populated in the page load. I do not
    check the PostBack value because I want to rebuild the Menu Control
    each page visit.


    The first time the Menu is built exactly as specified in the
    StaticItemTemplate, however, each pressing the postback button gives
    me an un-staticitemtemplated version of the menu.


    IOW on postback and rebuild of the menu, the itemtemplate (and thus
    styling) is removed or not even applied.


    Can anyone help???


    Here is the code to reproduce:


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


    <%@ Register Src="UserControls/Menu.ascx" TagName="Menu"
    TagPrefix="uc1" %>


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
    Menu1.Items.Clear();
    Menu1.Items.Add(new MenuItem("hello world1"));
    Menu1.Items.Add(new MenuItem("hello world2"));
    Menu1.Items.Add(new MenuItem("hello world3"));
    Menu1.Items.Add(new MenuItem("hello world4"));
    }


    </script>


    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:Menu ID="Menu1" runat="server">
    <StaticItemTemplate>
    <asp:Button ID="Button1" runat="server" Text='<%#
    Eval("Text") %>' />
    </StaticItemTemplate>
    </asp:Menu>
    <asp:Button runat="server" ID="btnButton" Text="Do a postback
    to rebuild the menu" />


    </div>
    </form>
    </body>
    </html>
     
    John123, Oct 30, 2007
    #1
    1. Advertising

  2. John123

    John123 Guest

    On Oct 30, 2:27 pm, John123 <> wrote:
    > Hi all,
    >
    > I am having a strange problem when using the ASP.NET (2.0) menu
    > control.
    > I have a menu control that gets populated in the page load. I do not
    > check the PostBack value because I want to rebuild the Menu Control
    > each page visit.
    >
    > The first time the Menu is built exactly as specified in the
    > StaticItemTemplate, however, each pressing the postback button gives
    > me an un-staticitemtemplated version of the menu.
    >
    > IOW on postback and rebuild of the menu, the itemtemplate (and thus
    > styling) is removed or not even applied.
    >
    > Can anyone help???
    >
    > Here is the code to reproduce:
    >
    > <%@ Page Language="C#" %>
    >
    > <%@ Register Src="UserControls/Menu.ascx" TagName="Menu"
    > TagPrefix="uc1" %>
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <script runat="server">
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > Menu1.Items.Clear();
    > Menu1.Items.Add(new MenuItem("hello world1"));
    > Menu1.Items.Add(new MenuItem("hello world2"));
    > Menu1.Items.Add(new MenuItem("hello world3"));
    > Menu1.Items.Add(new MenuItem("hello world4"));
    > }
    >
    > </script>
    >
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    > <head runat="server">
    > <title>Untitled Page</title>
    > </head>
    > <body>
    > <form id="form1" runat="server">
    > <div>
    > <asp:Menu ID="Menu1" runat="server">
    > <StaticItemTemplate>
    > <asp:Button ID="Button1" runat="server" Text='<%#
    > Eval("Text") %>' />
    > </StaticItemTemplate>
    > </asp:Menu>
    > <asp:Button runat="server" ID="btnButton" Text="Do a postback
    > to rebuild the menu" />
    >
    > </div>
    > </form>
    > </body>
    > </html>


    noone???
     
    John123, Nov 1, 2007
    #2
    1. Advertising

  3. John123

    beemer127 Guest

    On Oct 30, 8:27 am, John123 <> wrote:
    > Hi all,
    >
    > I am having a strange problem when using the ASP.NET (2.0) menu
    > control.
    > I have a menu control that gets populated in the page load. I do not
    > check the PostBack value because I want to rebuild the Menu Control
    > each page visit.
    >
    > The first time the Menu is built exactly as specified in the
    > StaticItemTemplate, however, each pressing the postback button gives
    > me an un-staticitemtemplated version of the menu.
    >
    > IOW on postback and rebuild of the menu, the itemtemplate (and thus
    > styling) is removed or not even applied.
    >
    > Can anyone help???
    >
    > Here is the code to reproduce:
    >
    > <%@ Page Language="C#" %>
    >
    > <%@ Register Src="UserControls/Menu.ascx" TagName="Menu"
    > TagPrefix="uc1" %>
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <script runat="server">
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > Menu1.Items.Clear();
    > Menu1.Items.Add(new MenuItem("hello world1"));
    > Menu1.Items.Add(new MenuItem("hello world2"));
    > Menu1.Items.Add(new MenuItem("hello world3"));
    > Menu1.Items.Add(new MenuItem("hello world4"));
    > }
    >
    > </script>
    >
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    > <head runat="server">
    > <title>Untitled Page</title>
    > </head>
    > <body>
    > <form id="form1" runat="server">
    > <div>
    > <asp:Menu ID="Menu1" runat="server">
    > <StaticItemTemplate>
    > <asp:Button ID="Button1" runat="server" Text='<%#
    > Eval("Text") %>' />
    > </StaticItemTemplate>
    > </asp:Menu>
    > <asp:Button runat="server" ID="btnButton" Text="Do a postback
    > to rebuild the menu" />
    >
    > </div>
    > </form>
    > </body>
    > </html>


    I am having the same problem. I found a workaround, but not a
    solution. Basically, I was using an image button. instead of using the
    postback property, I simply did a response.redirect() in the code
    behind (VB.NET). Unfortunately, that does not fix the problem,
    especially when you may be working with data-driven forms requiring a
    postback. I'm not sure what else to do at this point, so if you have
    found a solution, please let me know. :eek:)
     
    beemer127, Dec 19, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ilmar

    How to use a StaticItemTemplate?

    Ilmar, Aug 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    9,559
    Ilmar
    Aug 15, 2004
  2. Replies:
    0
    Views:
    5,149
  3. =?Utf-8?B?QUMgW01WUCBNQ01TXQ==?=

    Specifying style for subitems in the ASP Menu StaticItemTemplate

    =?Utf-8?B?QUMgW01WUCBNQ01TXQ==?=, Nov 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,098
    =?Utf-8?B?QUMgW01WUCBNQ01TXQ==?=
    Nov 15, 2006
  4. John123
    Replies:
    1
    Views:
    927
    John MJ Gorter
    Nov 6, 2007
  5. Andrew Jocelyn
    Replies:
    3
    Views:
    1,045
    Steven Cheng[MSFT]
    Jan 17, 2008
Loading...

Share This Page