Stack Overflow Error when clicking on MasterPage link.

Discussion in 'ASP .Net' started by thomasjgregg@yahoo.com, Mar 16, 2008.

  1. Guest

    I have a menu in the masterpage. It all works great until I click on
    the link that transfers to the page that I am on. When I do this it
    causes a stack overflow error. I can see why it is doing this but I
    am not sure what to do to fix it. Any Help would be appreciated.

    The code:
    <table cellspacing=0 cellpadding=5 width=770 border=0>
    <tr>
    <td width=130 valign=top>
    <asp:LinkButton ID="HomeLink" runat="server"
    CssClass="MenuLink" NavigateUrl="Default.aspx"
    OnClick="HomeLink_Click">Home</asp:LinkButton><br />
    <asp:LinkButton ID="AboutUsLink" runat="server"
    CssClass="MenuLink" NavigateUrl="AboutUs.aspx"
    OnClick="AboutUsLink_Click">About Us</asp:LinkButton><br />
    <asp:LinkButton ID="HowWeCanHelpLink" runat="server"
    CssClass="MenuLink" NavigateUrl="HowWeCanHelp.aspx"
    OnClick="HowWeCanHelpLink_Click">How we can help</asp:LinkButton><br /
    >

    <asp:LinkButton ID="ProductLink" runat="server"
    CssClass="MenuLink" NavigateUrl="Product.aspx"
    OnClick="ProductLink_Click">Product</asp:LinkButton><br />
    <asp:LinkButton ID="ContactUsLink" runat="server"
    CssClass="MenuLink" NavigateUrl="ContactUs.aspx"
    OnClick="ContactUsLink_Click">Contact Us</asp:LinkButton><br />
    </td>
    <td valign=top style="border-left:1px solid black;" >
    <asp:ContentPlaceHolder ID="MainHolder"
    runat="server"></asp:ContentPlaceHolder>
    </td>
    </tr>
    </table>

    public partial class MasterPage : System.Web.UI.MasterPage
    {
    User u = new User();
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Session.IsNewSession & !IsPostBack)
    {
    u.GetUserByUserName(Session["UserName"].ToString());
    UserLabel.Text = u.FirstName;
    }
    }
    protected void AboutUsLink_Click(object sender, EventArgs e)
    {
    Session.Add("UserName", u.UserName);
    Server.Transfer("AboutUs.aspx", true);
    }
    protected void HomeLink_Click(object sender, EventArgs e)
    {
    Session.Add("UserName", u.UserName);
    Server.Transfer("Default.aspx", true);
    }
    protected void HowWeCanHelpLink_Click(object sender, EventArgs e)
    {
    Session.Add("UserName", u.UserName);
    Server.Transfer("HowWeCanHelp.aspx", true);
    }
    protected void ProductLink_Click(object sender, EventArgs e)
    {
    Session.Add("UserName", u.UserName);
    Server.Transfer("Product.aspx", true);
    }
    protected void ContactUsLink_Click(object sender, EventArgs e)
    {
    Session.Add("UserName", u.UserName);
    Server.Transfer("ContactUs.aspx", true);
    }
    }
     
    , Mar 16, 2008
    #1
    1. Advertising

  2. Why don't you just check to see what the current page is? If it is the same
    as the link that was clicked, just return from the method and do nothing.
    -- Peter
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short Urls & more: http://ittyurl.net


    "" wrote:

    > I have a menu in the masterpage. It all works great until I click on
    > the link that transfers to the page that I am on. When I do this it
    > causes a stack overflow error. I can see why it is doing this but I
    > am not sure what to do to fix it. Any Help would be appreciated.
    >
    > The code:
    > <table cellspacing=0 cellpadding=5 width=770 border=0>
    > <tr>
    > <td width=130 valign=top>
    > <asp:LinkButton ID="HomeLink" runat="server"
    > CssClass="MenuLink" NavigateUrl="Default.aspx"
    > OnClick="HomeLink_Click">Home</asp:LinkButton><br />
    > <asp:LinkButton ID="AboutUsLink" runat="server"
    > CssClass="MenuLink" NavigateUrl="AboutUs.aspx"
    > OnClick="AboutUsLink_Click">About Us</asp:LinkButton><br />
    > <asp:LinkButton ID="HowWeCanHelpLink" runat="server"
    > CssClass="MenuLink" NavigateUrl="HowWeCanHelp.aspx"
    > OnClick="HowWeCanHelpLink_Click">How we can help</asp:LinkButton><br /
    > >

    > <asp:LinkButton ID="ProductLink" runat="server"
    > CssClass="MenuLink" NavigateUrl="Product.aspx"
    > OnClick="ProductLink_Click">Product</asp:LinkButton><br />
    > <asp:LinkButton ID="ContactUsLink" runat="server"
    > CssClass="MenuLink" NavigateUrl="ContactUs.aspx"
    > OnClick="ContactUsLink_Click">Contact Us</asp:LinkButton><br />
    > </td>
    > <td valign=top style="border-left:1px solid black;" >
    > <asp:ContentPlaceHolder ID="MainHolder"
    > runat="server"></asp:ContentPlaceHolder>
    > </td>
    > </tr>
    > </table>
    >
    > public partial class MasterPage : System.Web.UI.MasterPage
    > {
    > User u = new User();
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > if (!Session.IsNewSession & !IsPostBack)
    > {
    > u.GetUserByUserName(Session["UserName"].ToString());
    > UserLabel.Text = u.FirstName;
    > }
    > }
    > protected void AboutUsLink_Click(object sender, EventArgs e)
    > {
    > Session.Add("UserName", u.UserName);
    > Server.Transfer("AboutUs.aspx", true);
    > }
    > protected void HomeLink_Click(object sender, EventArgs e)
    > {
    > Session.Add("UserName", u.UserName);
    > Server.Transfer("Default.aspx", true);
    > }
    > protected void HowWeCanHelpLink_Click(object sender, EventArgs e)
    > {
    > Session.Add("UserName", u.UserName);
    > Server.Transfer("HowWeCanHelp.aspx", true);
    > }
    > protected void ProductLink_Click(object sender, EventArgs e)
    > {
    > Session.Add("UserName", u.UserName);
    > Server.Transfer("Product.aspx", true);
    > }
    > protected void ContactUsLink_Click(object sender, EventArgs e)
    > {
    > Session.Add("UserName", u.UserName);
    > Server.Transfer("ContactUs.aspx", true);
    > }
    > }
    >
     
    Peter Bromberg [C# MVP], Mar 17, 2008
    #2
    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. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    MasterPage -> Page -> MasterPage Code Access

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Apr 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    7,894
    Steven Cheng[MSFT]
    Apr 14, 2006
  2. Bon
    Replies:
    7
    Views:
    462
    Eliyahu Goldin
    Dec 26, 2006
  3. Kenneth McDonald

    Why stack overflow with such a small stack?

    Kenneth McDonald, Aug 30, 2007, in forum: Ruby
    Replies:
    7
    Views:
    262
    Kenneth McDonald
    Sep 1, 2007
  4. pavi
    Replies:
    0
    Views:
    1,343
  5. friday13
    Replies:
    3
    Views:
    200
    friday13
    Apr 28, 2007
Loading...

Share This Page