 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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>
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I use the method I mentioned a lot... I know it works.
Are you sure you have runat="server" in your body tag?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You are absolutely right it works perfectly. I had another issue in my script that wa causing a problem. 
Thanks!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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 ....
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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?
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
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:
// HTML head element must, of course, have runat="server" specified. 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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
... 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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You're missing the point. The point of this is to show how to add attributes to the body tag, not how to add script to the page. Of course, adding script to the page is one possible use for this, but as you said, this may not be the best way to do that. It is, however, the best way to gain access to the entire "body" object in server-side code so that you can make attribute additions, style changes, etc. I've done this many times, in fact, both in master pages and in my regular pages as well. I also recommend the use of the @MasterType directive on your "child" pages, so that you can refer to the master page by a strongly typed reference.
Kelly
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
basically, you can use the same masterpage and style it differently. <body id="homepage"> and <body id="downpage"> can be two completely different looking pages if you write your CSS correctly. this is a very useful idea.
DotNetDiscussion[^]
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Not bad, but I'd recommend you remove the set accessor for the property declaration. Otherwise, you could replace the body tag with an improper object inadvertently (a very bad thing, since it wouldn't properly update the hierarchy of the master page as the code is written now).
Kelly Leahy Milliman, Inc.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |