I have the below Place holder between the head tags on a master page which all pages at some stage inherit from:
<asp:ContentPlaceHolder ID="cphHead" runat="server" />
I then have the below content on a page that inherits from the master page:
<asp:Content ID="Content1" ContentPlaceHolderID="cphHead" Runat="Server">
<asp:Literal ID="litMetaTitle" runat="server" />
<asp:Literal ID="litMetaDescription" runat="server" />
<asp:Literal ID="litMetaKeywords" runat="server" />
<asp:ContentPlaceHolder ID="CphHeaderContent" runat="server" />
</asp:Content>
As you can see this has another place holder in it, from this page inherits another page with the below content:
<asp:Content ID="ContentHeader" runat="server" ContentPlaceHolderID="CphHeaderContent">
<asp:Literal ID="TheId" runat="server" />
</asp:Content>
The literal is being built with a string builder in the code behind:
private void xxx(Order order)
{
//...Building string with string builder
TheId.Text = xxx.ToString();
}
This literal is not appearing in the head of this page when I view it in the browser? Does anyone have any idea as to why? If I add something like below between the content tags:
<asp:Content ID="ContentHeader" runat="server" ContentPlaceHolderID="CphHeaderContent">
<asp:Literal ID="TheId" runat="server" />
<script src="/Media/Javascript/xxx.js"></script><--ADDED!
</asp:Content>
The <script src="/Media/Javascript/xxx.js"></script> will appear in the head? Its just the literal that wont? Why is this?
Related
I have this piece of code in my aspx page open a modal popup. I found this code online but for some reason the page refreshes and the popup does not appear. I tried several code snippets but the issue keeps on occurring. It must be an issue with my page.
This is my .aspx code
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<style type="text/css">
.ModalPopupBG
{
background-color: Gray;
filter: alpha(opacity=70);
opacity: 0.7;
}
.popup
{
background:white;
}
</style>
<script>
function onAgree() {
alert("Thank you for your approval")
}
function onDisagree() {
alert("I appreciate your feedback; i will work harder next time")
}
</script>
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<asp:Button ID="Button1" runat="server" Text="feedback"/>
<asp:Panel ID="Panel1" runat="server" CssClass ="popup">
please give me your feedback about the paragraph above?
<hr />
<asp:Button ID="btnagree" runat="server" Text="Agree" />
<asp:Button ID="btndisagree" runat="server" Text="Disagree" />
</asp:Panel>
<asp:ModalPopupExtender ID="ModalPopupExtender1"
runat="server"
TargetControlID ="Button1"
PopupControlID="Panel1"
BackgroundCssClass="modalBackground"
DropShadow="true"
OkControlID="btnagree"
CancelControlID="btndisagree"
OnOkScript="onAgree()"
OnCancelScript ="onDisagree()">
<Animations>
<OnShown>
<Fadein />
</OnShown>
<OnHiding>
<Fadeout />
</OnHiding>
</Animations>
</asp:ModalPopupExtender>
</div>
</asp:Content>
I have 3 image buttons on the left, top and right of the main body content.
I want these fixed in position so that when I scroll up or down, these remain in position.
This page has a master page. I'm using ContentPlaceHolders:
<asp:Content ID="Content1" ContentPlaceHolderID="left_col_fbodyContentPlaceHolder"
runat="Server">
<asp:ImageButton ID="LeftImageButton" runat="server" Width="233px" Height="100%" ImageUrl="~/images/100_3445sr194k.jpg" PostBackUrl="~/test1.aspx" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="upper_body_ContentPlaceHolder" runat="Server">
<asp:ImageButton ID="TopImageButton" runat="server" Width="770px" Height="40px" ImageUrl="~/images/100_3496sr194k.jpg" PostBackUrl="~/test1.aspx" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="right_col_fbodyContentPlaceHolder"
runat="Server">
<asp:ImageButton ID="RightImageButton" runat="server" Width="233px" Height="100%" ImageUrl="~/images/100_3496sr194k.jpg" PostBackUrl="~/test1.aspx" />
</asp:Content>
If it's possible, I'm hoping someone can show me how.
AjaxControlToolkits's AlwaysVisibleControl solves your problem. For more details see this
Option 1.: use Fixed position in css
<div class='fixedDiv'>
<asp:ImageButton ID="LeftImageButton" runat="server" Width="233px" Height="100%" ImageUrl="~/images/100_3445sr194k.jpg" PostBackUrl="~/test1.aspx" />
</div>
In css:
.fixedDiv{
position:fixed;
}
Another option is set fixed height to body, and overflow:auto to the div which contains the content. the scroll appears on the content div while the screen stay fixed.
<asp:Content ID="Bodycontent" ContentPlaceHolderID="BodyContent"
runat="Server">
<div style='height:900px;overflow:auto'>
</div>
</asp:Content>
I'm working on web application based on ASP.Net and C#.
When i click the button in Content page, I want to pass data(string) to Masterpage and show it to the user. I know the technique and codes but the problem is with Ajax.
Since the button in content page is inside of Updatepanel, when i click the button, message will not be appear in masterpage. Because only part of the page wil be refrsh and i do not know, how to refesh master page
Code inside contentpage:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder_Body_Member" ...>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ... ></asp:TextBox>
<asp:Button ID="ShowText" ... />
</ContentTemplate>
</asp:UpdatePanel>
Code inside masterPage (actually this is a nested masterPage):
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder_TopRightSide" runat="server"> ... </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder_Menu" runat="server"> ... </asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder_Body" runat="server">
<asp:ContentPlaceHolder ID="ContentPlaceHolder_Body_Member" runat="server"> </asp:ContentPlaceHolder>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder_Footer" runat="server">
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<ContentTemplate>
<asp:Label ID="DataFromPage" ... ></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Button is insde of "ContentPlaceHolder_Body_Member" and the label is inside of "ContentPlaceHolder_Footer"
To achieve the result that you need you just need to make a little change on your Master page design like the code below:
On your master-page place the content-place-holder inside the update panel first:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="DataFromPage" runat="server" Text="Label"></asp:Label>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
Then in your Content page you will have something like this (almost the same as yours)
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Finally in your code-behind on button-click event you could assign your value to the master page's label control like the code shown below:
protected void Button1_Click(object sender, EventArgs e)
{
Label myLabel = Page.Master.FindControl("UpdatePanel1").FindControl("DataFromPage") as Label;
myLabel.Text = "this is a message from my content page";
}
And here is the result :
UPDATE 1
Ok remember if you have a nested update panel then the way you find the control in that one is a bit different also if you need to make changes on the other content page you need to force the update panel to make the changes in your code behind, so your code should be like this:
//your button control's event needs to find the update panel and the label both:
protected void Button1_Click(object sender, EventArgs e)
{
UpdatePanel myUpdatePanel = Page.Master.Master.FindControl("ContentPlaceHolder_Footer").FindControl("UpdatePanel") as UpdatePanel;
Label myLabel = Page.Master.Master.FindControl("ContentPlaceHolder_Footer").FindControl("DataFromPage") as Label;
myLabel.Text = "this is a message from my content page";
myUpdatePanel.Update(); //force the panel to get updated
}
Cheers
I have a page that works fine with multiple a grid and multiple buttons. The page works fine until I add an asp:UpdatePanel. Then I get the following message pushing any of my buttons:
Sys.WebForms.PageRequestManagerServerErrorException: Input string was not in a correct format.
There is no javascript on the page just straight html.
Here is the page:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPages/Site.Master" AutoEventWireup="true"
CodeBehind="TestUpdatePanel.aspx.cs" Inherits="ASCWeb.TestUpdatePanel" %>
<asp:Content ID="mHeadContent" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="mBodyContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel ID="pnlUpdate" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtUser" runat="server" />
<asp:ImageButton ID="btnAdd" runat="server" ImageUrl="~/Images/Add.png" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
If I take the TextBox out, it works fine. Nothing is in the code behind.
What would cause this?
Thanks
As per experience, I only encounter that exception when calling Javascript from codebehind, like when using ScriptManager.RegisterClientScriptBlock() to call window.alert(), for instance. But for this issue, I think this resolves it: http://forums.asp.net/t/1823287.aspx/2/10.
I have 2 master pages that are nested.this is main master page code for example:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPageMaster.master.cs" Inherits="MasterPageMaster" %>
<!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>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtMasterPageMaster" ClientIDMode="Static" runat="server"></asp:TextBox>
<div style="background-color:Aqua;height:40px;">
Some Text
</div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
and the nested master page:
<%# Master Language="C#" MasterPageFile="~/MasterPageMaster.master" AutoEventWireup="true"
CodeFile="MasterPageNested.master.cs" Inherits="MasterPageNested" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:Panel runat="server" ID="panelMain" BackColor="lightyellow">
<h2>
Child master</h2>
<asp:Panel runat="server" ID="panel1" BackColor="lightblue">
<p>
This is child master content.</p>
<asp:ContentPlaceHolder ID="ChildContent1" runat="server" />
</asp:Panel>
<asp:Panel runat="server" ID="panel2" BackColor="pink">
<p>
This is child master content.</p>
<asp:ContentPlaceHolder ID="ChildContent2" runat="server" />
</asp:Panel>
<br />
</asp:Panel>
</asp:Content>
and I create a page based on this nested master page:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPageNested.master" AutoEventWireup="true" CodeFile="PageMasterPageNested.aspx.cs" Inherits="PageMasterPageNested" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ChildContent1" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ChildContent2" Runat="Server">
<asp:Button ID="Button1" runat="server" Text="Button" Height="66px"
onclick="Button1_Click" Width="196px" />
</asp:Content>
I want in click of Button1 get text of main master page.
How I can do this?
In PageMasterPageNested.aspx:
TextBox txtBox = this.Master.Master.FindControl("txtMasterPageMaster") as TextBox;
Should work. Give it a try. Hope it helps.
This works in any case. especially if you dont know or care how many master pages you nested. Hope it helps :)
MasterPage tmp = this.Master;
while (tmp.Master != null)
{
tmp = tmp.Master;
}
var control = tmp.FindControl("form1");