LinkButton in MasterPage

  • Thread starter Thread starter MRW
  • Start date Start date
M

MRW

I have a simple linkbutton and a function when it's clicked. It works
perfectly in a regular .aspx page. However, when I place it inside the
ContentPlaceHolder, it no longer works. It does *something*, but
certainly not the function, which is also in the ContentPlaceHolder.
This is also true concerning any events in there.

Any ideas?

Thanks for any help!
 
You haven't shown us the troublesome code so its hard to know what you're
trying to do. Here's a linkbutton in a master page that does something... it
puts the date on the label.

Let us know more about your problem and show the code?

Ken
Microsoft MVP [ASP.NET]

<%@ Master Language="VB" %>

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

<script runat="server">

Protected Sub LinkButton1_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = "Link clicked at " & Now.ToLongTimeString
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Linkbutton master</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:linkbutton id="LinkButton1" runat="server"
onclick="LinkButton1_Click">Click Me!</asp:linkbutton><br />
<br />
<asp:label id="Label1" runat="server"></asp:label><br />
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
<br />
</div>
</form>
</body>
</html>
 
Good point! :) Here's an abriged version:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
Title="Employee Menu" AutoEventWireup="true"%>

<script runat="server">
Protected Sub gotoAOB1(ByVal sender As Object, ByVal e As
System.EventArgs)
Response.Redirect("/index.aspx")
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent"
Runat="Server">
<asp:LinkButton ID="LinkButton1" runat="server"
OnClick="gotoAOB1">LinkButton</asp:LinkButton>
<br />
</asp:Content>

---
When it's on it's own page, it's fine. But when it's inside the
contentPlaceHolder... well... it just sits there!

Thanks for any help!
You haven't shown us the troublesome code so its hard to know what you're
trying to do. Here's a linkbutton in a master page that does something... it
puts the date on the label.

Let us know more about your problem and show the code?

Ken
Microsoft MVP [ASP.NET]

<%@ Master Language="VB" %>

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

<script runat="server">

Protected Sub LinkButton1_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = "Link clicked at " & Now.ToLongTimeString
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Linkbutton master</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:linkbutton id="LinkButton1" runat="server"
onclick="LinkButton1_Click">Click Me!</asp:linkbutton><br />
<br />
<asp:label id="Label1" runat="server"></asp:label><br />
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
<br />
</div>
</form>
</body>
</html>

MRW said:
I have a simple linkbutton and a function when it's clicked. It works
perfectly in a regular .aspx page. However, when I place it inside the
ContentPlaceHolder, it no longer works. It does *something*, but
certainly not the function, which is also in the ContentPlaceHolder.
This is also true concerning any events in there.

Any ideas?

Thanks for any help!
 
Did you remember to change the ID of the ContentPlaceHolder so they match?
You seem to be using the name "MainContent".

Here's some sample code that works for me. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Master Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Master Page Tester</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="MainContent" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>


<%@ page autoeventwireup="true"
language="VB" masterpagefile="~/MasterPage.master"
title="Employee Menu" %>

<script runat="server">
Protected Sub gotoAOB1 _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
Response.Redirect("/index.aspx")
End Sub
</script>

<asp:content id="Content1" runat="Server"
contentplaceholderid="MainContent">
<asp:linkbutton id="LinkButton1"
runat="server" onclick="gotoAOB1">
LinkButton</asp:linkbutton>
<br />
</asp:content>


MRW said:
Good point! :) Here's an abriged version:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
Title="Employee Menu" AutoEventWireup="true"%>

<script runat="server">
Protected Sub gotoAOB1(ByVal sender As Object, ByVal e As
System.EventArgs)
Response.Redirect("/index.aspx")
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent"
Runat="Server">
<asp:LinkButton ID="LinkButton1" runat="server"
OnClick="gotoAOB1">LinkButton</asp:LinkButton>
<br />
</asp:Content>

---
When it's on it's own page, it's fine. But when it's inside the
contentPlaceHolder... well... it just sits there!

Thanks for any help!
You haven't shown us the troublesome code so its hard to know what you're
trying to do. Here's a linkbutton in a master page that does something...
it
puts the date on the label.

Let us know more about your problem and show the code?

Ken
Microsoft MVP [ASP.NET]

<%@ Master Language="VB" %>

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

<script runat="server">

Protected Sub LinkButton1_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = "Link clicked at " & Now.ToLongTimeString
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Linkbutton master</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:linkbutton id="LinkButton1" runat="server"
onclick="LinkButton1_Click">Click Me!</asp:linkbutton><br />
<br />
<asp:label id="Label1" runat="server"></asp:label><br />
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
<br />
</div>
</form>
</body>
</html>

MRW said:
I have a simple linkbutton and a function when it's clicked. It works
perfectly in a regular .aspx page. However, when I place it inside the
ContentPlaceHolder, it no longer works. It does *something*, but
certainly not the function, which is also in the ContentPlaceHolder.
This is also true concerning any events in there.

Any ideas?

Thanks for any help!
 

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

Back
Top