Stack Overflow Error when clicking on MasterPage link.

  • Thread starter Thread starter thomasjgregg
  • Start date Start date
T

thomasjgregg

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"
<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);
}
}
 
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


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"
<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);
}
}
 
Back
Top