 |
|
 |
If you get error "Could not load type... try adding the namespace to the MasterType declaration:
instead of
<%@ MasterType TypeName="Master" %>
try
<%@ MasterType TypeName="Namespace.Master" %>
|
|
|
|
 |
|
 |
hi
to solve this problem you should ASP namespace and then your MasterPage Class.
example:
My MasterPage Class is :
public partial class Pages_Window : System.Web.UI.MasterPage
{
public HtmlGenericControl BodyTag
{
get
{
return MasterPageBodyTag;
}
set
{
MasterPageBodyTag = value;
}
}
}
and in aspx page directive is :
<%@ MasterType TypeName="ASP.pages_window_master" %>
also you can use ASP.pages_window_master in code behind of your aspx page for access to
Master.BodyTag
|
|
|
|
 |
|
 |
hi
to solve this problem you should ASP namespace and then your MasterPage Class.
example:
My MasterPage's Name is : Window.master and Window.master.cs
My MasterPage Class is :
public partial class Pages_Window : System.Web.UI.MasterPage
{
public HtmlGenericControl BodyTag
{
get
{
return MasterPageBodyTag;
}
set
{
MasterPageBodyTag = value;
}
}
}
and in aspx page directive is :
<%@ MasterType TypeName="ASP.pages_window_master" %>
also you can use ASP.pages_window_master in code behind of your aspx page for access to
Master.BodyTag
-------------
Hamed KamalHamedani From Hamedan,Hamedan,Iran
good luck
|
|
|
|
 |
|
 |
I am not a programmer and I bet this solution is BAD but it works . ..
I put the <body> tag INSIDE a content place holder on the master page.
For most content pages I don't want to change it but on my map page I need a couple of google map related things so on those pages I over ride the default content with my revised body tag
<body onload="initialize()" onunload="GUnload()>
So it looks like
Master page
<asp:contentplaceholder ID="bodytag" runat="server">
<body>
</asp:contentplaceholder>
Most pages don't call that place holder - the default gets used
On the map master page
<asp:Content ID="Content0" ContentPlaceHolderID="BodyTag" Runat="Server">
<body onload="initialize()" onunload="GUnload()">
</asp:Content>
It works but if it is really bad practice please remove this post.
Good luck!
|
|
|
|
 |
|
 |
exactly what i was looking for. needed javascript to disable back navigation in onunload event, but only for certain conditions within a content page.
thanks.
|
|
|
|
 |
|
 |
Does anyone have samples of doing this with VB?
I can't get this to work, I have to be close but just missing something, if anyone has a sample using VB with Code Behind file, I would sure appreciate it if you would be willing to share it.
Thanks
AD34
|
|
|
|
 |
|
 |
I am new to asp.net, so this might be a silly question
Most tutorials i have followed, has a masterpage. The contentplaceholder is a holder for the aspx pages and usercontrols
are where you can have MenuSystem, and so on in a usercontrol and link it to the masterpage.
isent it better to make a <body> in a aspx page global rather than the master's body? If you have a create Textbox button control inside a user control, in the masterpage, you would rather create to a certain aspx page than the masterpage body - or am i wrong??? </body>
|
|
|
|
 |
|
 |
If you set your master page body tag to:
<body id="master_body" runat="server">
Then all you need to do is add this on any page that uses the master:
public void Page_Load(Object sender, EventArgs e)
{
//Inject onload and unload
HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("master_body");
body.Attributes.Add("onload", "someFunction()");
body.Attributes.Add("onunload", "anotherFunction()");
}
I don't use code behind pages and this works great.
|
|
|
|
 |
|
 |
I like this simple approach but can not get it to work. I think I am missing something simple.
In my Content page I have:
function void SayHello() {
alert("Hello");
}
and in the Content page code behind:
body.Attributes.Add("onload", "SayHello()");
everything else is the same as your post.
|
|
|
|
 |
|
 |
I use the method I mentioned a lot... I know it works. Are you sure you have runat="server" in your body tag?
|
|
|
|
 |
|
 |
You are absolutely right it works perfectly. I had another issue in my script that wa causing a problem.
Thanks!
|
|
|
|
 |
|
 |
Hi,
A long time You wrote this, I know but I'm trying to convert Your code and use in VB. It would really be nice if You could help me.
Thanks
|
|
|
|
 |
|
 |
I have a similar write up I did on my blog. I essentially do the same thing to provide an alternative to using FindControl for accessing the properties of controls on MasterPages from other Content pages. This allows you to access for instance the text property of a TextBox control on the MasterPage from a Content page in a strongly type manner.
http://lspence.blogspot.com
lspence.blogspot.com
|
|
|
|
 |
|
 |
I found this solution very interesting, cause I'm trying to solve the same issue. Trying to run a onload javascript function from the content page.
What about if also have a onload function in the Master Page?
<body id="MasterPageBodyTag" runat="server" önload="setInterval('refeshLogo()',10000);">
Currently I'm getting a error "Too many characters in character literal".
But it works if I remove the onLoad function from Master page.
Any thoughts?
I've also looked at Page.ClientScript.RegisterStartupScript which will works okay to add a onLoad function in content page, BUT I also need a onUnLoad event to that I need to attach code to ... but not sure how with ClientScript. It makes sense I should be able to use the code from this article to accomplish, but the error I'm getting isn't giving me much hope.
Thanks ....
|
|
|
|
 |
|
 |
Hi, Great article! I'm trying to read attribute values from within a user control. So I could easily configure the user control to behave in certain ways depending on it's tag attribute values. Currently I'm having difficulties accessing it's tag's attributes in the Master page. Can anyone point me in the right direction? The Master page tag looks like this: <hnuc:UCIHeaderNav id="UsRTab" runat="server" /> and it renders custom html just fine, but I don't know how to access it's defining tag's attributes from within the control itself. What am I missing?
|
|
|
|
 |
|
 |
Great tip, but one question. Have you, or anybody else, ever been able to figure out how to modify the base element in the header? Currently, I'm just doing something like this:
HtmlGenericControl baseElm = new HtmlGenericControl("base");
baseElm.Attributes["href"] = "Some/Sub/Folders/";
Page.Header.Controls.Add(baseElm);
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA www.defaultn.com
|
|
|
|
 |
|
 |
... because when I added attributes to my body tag it wiped out all other body tag attributes in my actual stylesheet.
The stylesheet is loaded in code-behind after a browser check (stewwwwpid IE6 makes "gymnastics" my second hobby) in the Page_Load method that also displays different header and logos if its IE6. When I attempt to alter the <body> properties in the same manner, by appending styles at runtime to those in the stylesheet it has no effect.
NOW, obviously I could do another browser check on the client side to control specific background attributes with JavaScript but I'd like to only do that once per page load frankly and not maintain two spots for browser sniffs..
Let me clarify, I didn't abandon YOUR solution, I came to this same solution on my own after a few hours and even more grey hairs, seeing YOUR solution gave me hope I actually was on the right track... I'm sorry if this is a stupid question, i'm a designer doing c# to make my designs work, worse than a n00b I tell ya.
|
|
|
|
 |
|
 |
You have any Idea how to access the BodyTag from a Control???
thanks in advance,
Omid
|
|
|
|
 |
|
|
 |
|
 |
very nice ! in this way i can do more things i want! thx!
|
|
|
|
 |
|
 |
Hi
You can use this idea to access all HTML elements contained in the MasterPage, not just the body element.
You can access the meta tags and the html tag, for example.
Going a step further you can reuse this in all your projects and a good way to do that is to use the Page Controller design design.
Regards,
Adam Tibi
Make it simple, as simple as possible, but not simpler.
|
|
|
|
 |
|
 |
For the life of me I can't see this being a good idea. There are such better ways to attach javascript events to a page.
|
|
|
|
 |
|
 |
OK - I'm always willing to learn. What would be another way to do this?
|
|
|
|
 |
|
 |
Currently I'm not sure that this is the exact syntax but I think that you can register a client script with a code like this:
page.load = yourJsFunction;
... or a similar code.
But in my opinion your solution is a little better (more object oriented ...).
Davide
|
|
|
|
 |
|
 |
Its much easier to maintain if you keep all the code in the codebehind.
I used this approach for adding an onresize handler for the few pages that needed it.
and also to change the scroll to be no.
I even know of a way to change the body to scroll ="no" besides this, though im sure there is a way.
thanks for the post
|
|
|
|
 |