Stack Overflow Error when clicking on MasterPage link.

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

Peter Bromberg [C# MVP]

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top