I had asked a couple of question about multilanguage in asp.net and I am very grateful because the answers have been of much help.
I now face another problem.
I have the page directive:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="Galeria.aspx.cs" Inherits="TerapiaFisica.Galeria" %>
What I want is to make the Title multilanguage.
I know i can do that from code behind with something like this:
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = (string)GetLocalResourceObject("PageTitle");
}
But that's exactly what i don't want to do. I want to make that title multilanguage from the tag in the page directive of the aspx.
Anyone can tell me what to do?
I tried this two options but none of them works:
<%# Page Title=" <%= GetGlobalResourceObject("Global", "PageTitle") %>"
and
<%# Page Title="<asp:Localize Text="<%$ Resources: Global, PageTitle %>"
Will this work for you?
<head>
<title><%= GetGlobalResourceObject("Global", "PageTitle") %></title>
</head>
I don't have my IDE in front of me, but the one you wrote (below) looks wrong
<%# Page Title=" <%= GetGlobalResourceObject("Global", "PageTitle") %>"
Did you try
<title>
<%= GetGlobalResourceObject("Global", "PageTitle") %>
<title>
Related
I followed the tutorial: Getting Public Property Values from the Source Page on MSDN and I started a fresh Web Forms site and created the below two pages. They work just fine. Now, if I copy paste these into my other Web Forms project then PreviousPage == null. I have no idea what the issue could be. There is no errors whatsoever. I just get
messageSTr.Text = "Not a cross-page post.";
UPDATE: I deleted the MasterPage reference in the page declaration and im still getting the error. I copied this projects web.config to the other working one and it still works. Its not my web config, I am at a complete loss here. This is a vital tool that I need for my application.
This page submits to page 1
<%# Page
Title=""
Language="C#"
MasterPageFile="~/Site.Master"
AutoEventWireup="true"
CodeBehind="WebForm2.aspx.cs"
Inherits="WebApplication5.WebForm2" %>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<asp:Button id="button1" Text="Submit to PostBackUrl" PostBackUrl="~/WebForm1.aspx" runat="server"/>
This page receives the submit
<%# Page
Title=""
Language="C#"
MasterPageFile="~/Site.Master"
AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication5.WebForm1" %>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<asp:Label ID="messageSTr" runat="server"></asp:Label>
WebForm1.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
if (PreviousPage.IsCrossPagePostBack == true)
{
messageSTr.Text = PreviousPage.imaliveStr;
}
}
else
{
messageSTr.Text = "Not a cross-page post.";
}
}
The problem was the FriendlyUrls nuget package was removing the .aspx after my page names so my target page was not WebForm2.aspx but just WebForm2. This made the previous page null.
I have a feeling I'm missing one small thing. I have very simple page, created from the ASP.NET templates in VS2010. My Default.aspx consists of simply the following code. The Site.Master page is doing what it's supposed to.
<%#Page
Title="Home Page"
Language="C#"
MasterPageFile="~/Site.master"
AutoEventWireup="true"
CodeBehind="Default.aspx.cs"
Inherits="UserControlTest._Default" %>
<%#Register
TagPrefix="tsi"
Namespace="UserControlTest.Controls"
Assembly="UserControlTest" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<!-- HERE BE DRAGONS -->
<tsi:BigHelloBanner runat="server" />
<tsi:SmallHelloBanner runat="server" />
</asp:Content>
BigHelloBanner contains this:
<%#Control
Language="C#"
AutoEventWireup="true"
Visible="true"
CodeBehind="BigHelloBanner.ascx.cs"
Inherits="UserControlTest.Controls.BigHelloBanner" %>
<h1>HI!</h1>
Both the codebehind files in both objects are empty, and inherit from UserControl. The behavior is the same inheriting from Control. When I view-source on the rendered output, nothing from the HelloBanners is output, except some newlines. The HERE BE DRAGONS comment is visible, which indicates to me that the master page and all that works fine. I am expecting to see the <h1>HI!</h1> markup in the output as well. What am I missing? This seems really basic.
It looks like that you're referring to the empty code-behind class instead of the ASCX file with the output. Use the src attribute in your #Register directive:
<%#Register
TagPrefix="tsi"
TagName="BigHelloBanner"
Src="BigHelloBanner.ascx" %>
I can't see the src attribute here where is your control held ?
<%#Register
TagPrefix="tsi"
Namespace="UserControlTest.Controls"
Assembly="UserControlTest"
src="?" %>
Since BigHelloBanner is a web user control, you should try registering it like this:
<%#Register TagPrefix="tsi" TagName="BigHelloBanner" Src="~/pathToUserControls/BigHelloBanner.ascx" %>
Don't you still need to give an ID to each control instance?
I've created very simple web site for the test purposes. Only one master page and one content page.
My content page looks like this:
<%# Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="TestDiv1">bla bla</div>
<div id="TestDiv2">ble ble</div>
</asp:Content>
Now, based on some condition I would like to show/hide a given div. So I am trying to reach one of those divs by Controls collection, like this:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ContentPlaceHolder myContent = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1");
myContent.FindControl("TestDiv1").Visible = false; //this is not working
}
}
}
}
But the above example is not working. None of the two div control exists in the myContent.Controls collection. If I place for example a TextBox on my content page, I can reach it through Controls.
So what should I do to be able to access the div control?
your divs are HTMLcontrols, try to add them the tag runat="server"
<div id="TestDiv1" runat="server">bla bla</div>
That should solve your issue.
You need to set runat="server" on the divs.
I recently started using Masterpages, the thing is I would like to add text in code to an asp:Content tag.
So my content page markup code is:
<%# Page Language="C#" MasterPageFile="~/Template.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ASP_Test_WebApp.Default" %>
<asp:Content id="TEST" ContentPlaceHolderID="Main" Runat="Server" />
So now I would like to add Contents to the "TEST" id incode.
But my in code doesn't recognize TEST. If I don't use a masterpage and I give an id to a tag my in code reconigzes it, but now that I started using masterpages it doesn't.
What am I doing wrong?
Content tags don't have any UI on their own, you need to add controls inside them that you can then address in your code e.g.
<%# Page Language="C#" MasterPageFile="~/Template.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ASP_Test_WebApp.Default" %>
<asp:Content id="TEST" ContentPlaceHolderID="Main" Runat="Server" >
<asp:label runat="server" id="MyLabel"/>
</asp:content>
public partial class Default: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MyLabel.Text = "StackOverflow rocks!"
}
}
You don't need that ID. Try to add your content like: this.Controls.Add(mycontentcontrol)
I'm trying to do the following in a aspx page:
<%# Page Language="C#" EnableSessionSTate="true" ValidateRequest="False" Inherits="MyProject.CodeBehind.MYWF.SiteWF" MasterPageFile="~/_layouts/application.master" %>
<asp:Content ID="Content5" ContentPlaceHolderID="PlaceHolderPageDescription" runat="server">
<% if (!isOld) %>
<% { %>
<p>display this</p>
<% } %>
</asp:Content>
isOld is a public bool variable from the cs file mentioned in the namespace.
But unfortunately it gave me an unknown error.
I could do something similar in JSPs, but after googling around for a while, I'm not so sure whether the above is achievable in ASP.NET? (Am I missing a tag declaration, or do I have to write the entire tag lib myself?)
Thanks.
EDIT: I just got an unknown error. I have a feeling that the code above has either the wrong syntax or are totally off the wrong track. I tried the following code, and there was no error, but the bool variable is always false:
<% #if !isOld %>
<p> display this</p>
<% #endif %>
in your code front:
<%# Page Language="C#" EnableSessionSTate="true" ValidateRequest="False" Inherits="MyProject.CodeBehind.MYWF.SiteWF" MasterPageFile="~/_layouts/application.master" %>
<asp:Content ID="Content5" ContentPlaceHolderID="PlaceHolderPageDescription" runat="server">
<asp:PlaceHolder runat="server" id="PlaceHolderIsOld">
<p>display this</p>
</asp:PlaceHolder>
</asp:Content>
and then in your code behind:
protected void Page_Load(object sender, EventArgs e){
PlaceHolderIsOld.Visible = IsOld;
}