How to update "slave" content pages using updatepanel? - asp.net

I am creating an asp website using a Master page. I have some links inside the content page. I want to surf them using updatepanel, leaving the master page content intact. How do I achieve that?
Master Page
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="TestJquery.Site1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
this is master
<% Response.Write(DateTime.Now); %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Default.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="TestJquery._default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
This is slave
<asp:HyperLink NavigateUrl="default2.aspx" runat="server">default.aspx</asp:HyperLink>
</asp:Content>
Default1.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="default2.aspx.cs" Inherits="TestJquery.default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
this is slave
<asp:HyperLink NavigateUrl="default.aspx" runat="server">default</asp:HyperLink>
</asp:Content>

Related

Masterpage blocking search bar

I have a page with a gridview that displays results from a query and has paging and a search bar. It works fine when I load it by itself with not master page however when I add the master page to it all the controls disappear. below is the code with the master page and without
<%# Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default3.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent"
Runat="Server">
<%# Import Namespace="GridView" %>
<div>
<div align="center" class="padded" >
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
Font-Size="Large" OnSelectedIndexChanged="Refresh_Click">
</asp:DropDownList>
<asp:Button ID="Refresh" runat="server" OnClick="Refresh_Click"
Text="Search" Visible="False" />
</div>
<div>
<cc1:HTMLGridView ID="HTMLGridView1" runat="server"
OnRowDataBound="OnRowDataBound2"/>
</div>
Here is the code that works with no master page
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs"
Inherits="_Default" %>
<%# Register assembly="GridView" namespace="GridView" tagprefix="cc1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div align="center" class="padded" >
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
Font-Size="Large" OnSelectedIndexChanged="Refresh_Click">
</asp:DropDownList>
<asp:Button ID="Refresh" runat="server" OnClick="Refresh_Click"
Text="Search" Visible="False" />
</div>
<cc1:HTMLGridView ID="HTMLGridView1" runat="server"
OnRowDataBound="OnRowDataBound2" allowDeleting="False" allowEditing="False"
allowView="False"/>
</form>
</body>
</html>
I also added the reference to the web.config file but I have had no luck
<add tagPrefix="cc1" namespace="GridView" assembly="GridView" />
Where am I going wrong?
Try adding
<%# Import Namespace="GridView" %>
before
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent"
Runat="Server">

Master page content not showing up in child

I know there is something I am missing on this
But am unable to figure out that
I have this master page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Mains.master.cs" Inherits="Sportsstop.Mains" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sports Stop</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
N there is this Child page which should merge with the above master page:
<%# Page Title="" Language="C#" MasterPageFile="~/Mains.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Sportsstop.Home" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server" >
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
Your textbox should be in child page, inside ContentPlaceholder1. I think that the one in master page is ignored.
If you want to have TextBox in master page, it cannot be inside ContentPlaceholder
Think about placeholder as a place, where the content from child page gets injected

Does disabling viewstate in a page do anything if it has a masterpage with it enabled?

I have a page that uses a master page.
I disabled viewstate on the page (not the master page), and I didn't notice that the viewstate was reduced.
Curious if the masterpage setting will override it?
In my testing setting EnabledViewState = "False" will not reduce the page's view state while setting ViewStateMode="Disabled" will decrease the viewstate size
Master Page
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="ViewStateTest.master.cs" Inherits="Sample.ViewStateTest" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
Child Page
<%# Page Title="" Language="C#" MasterPageFile="~/ViewStateTest.master" AutoEventWireup="true" CodeBehind="ViewstateTestPage.aspx.cs" Inherits="Sample.ViewstateTestPage" ViewStateMode="Disabled" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:TextBox runat="server"></asp:TextBox>
</asp:Content>

Master Pages using Side Panels

I have used Master Pages with ASP.Net for some time. I have been able to develop Master pages with header and footing content but never sucessful with side panels.
What this project needs is a Main Master page with header and footer contents. Then another master page that uses the first master page and has it's content of the left side of the remaining middle. The Detail will go to the right with the left master content about one third and the detail about two third.
A working example would be good if possible.
Thanks.
Bob
Possibly looking for nested master pages?
Site.master
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="MySite.SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</form>
</body>
Nested.master
<%# Master Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Nester.master.cs" Inherits="MySite.NestedMaster" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div style="float:left;width:200px;margin-right:5px;">
<asp:ContentPlaceHolder runat="server" ID="LeftNavigation"></asp:ContentPlaceHolder>
</div>
<div style="float:left;width:440px;margin-right:5px;>
<asp:ContentPlaceHolder runat="server" ID="MainContents"></asp:ContentPlaceHolder>
</div>
<div style="clear:both;"></div>
</asp:Content>
Default.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Nested.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MySite.Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="LeftNavigation" runat="server">
<p>Left navigation content</p>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContents" runat="server">
<p>Body content</p>
</asp:Content>

UpdatePanel in a UserControl (a nested Forms problem)

I have problem with my UserControl. It has inside the UpdatePanel, but it must be placed inside the tag to get worked (otherwise, the PostBack is not asynchronous)
The problem is, if I put that UserControl in e.g. Default.aspx page, the error appears
"A page can have only one server-side Form tag"
how to cope with that ?
[edit]
the UserControl.ascx code:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="PodmiotyZwolnioneCtrl.ascx.cs" Inherits="FormularzPodatkowy.PodmiotyZwolnioneCtrl" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<link href="AjaxStyle.css" rel="stylesheet" type="text/css" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<form id="form1" runat="server">
<div>
<asp:UpdatePanel ID="UpdatePanel1"
UpdateMode="Conditional"
runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel content</legend>
<!-- Other content in the panel. -->
<%=DateTime.Now.ToString() %>
<br />
<asp:Button ID="Button1"
Text="Refresh Panel"
runat="server" />
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
the WebForm1.aspx code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="FormularzPodatkowy.WebForm1" %>
<%# Register src="PodmiotyZwolnioneCtrl.ascx" tagname="PodmiotyZwolnioneCtrl" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<uc1:PodmiotyZwolnioneCtrl ID="PodmiotyZwolnioneCtrl1" runat="server" />
</form>
</body>
</html>
Your code should be:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="PodmiotyZwolnioneCtrl.ascx.cs" Inherits="FormularzPodatkowy.PodmiotyZwolnioneCtrl" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<link href="AjaxStyle.css" rel="stylesheet" type="text/css" />
<div>
<asp:UpdatePanel ID="UpdatePanel1"
UpdateMode="Conditional"
runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel content</legend>
<!-- Other content in the panel. -->
<%=DateTime.Now.ToString() %>
<br />
<asp:Button ID="Button1"
Text="Refresh Panel"
runat="server" />
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</div>
It looks like you converted a page to a control and forgot to remove the page-specific elements
Also, if your postbacks are not asynchronous, look at your web.config for:
<xhtmlConformance mode="Legacy"/>
and change it to:
<xhtmlConformance mode="Transitional"/>
I just spent three days at work finding that solution to UpdatePanel always posting back to the server.
You should check both the usercontrol and the page and make sure that you only have one <form id='form1' runat='server'> tag in your markup. Having more than one will give you the error that you're experiencing.
Good luck, and hope this helps some.

Resources