Adding a ContentPlaceHolder to site.master - asp.net

Apologies for the terribly newb question. We're currently implementing Google Web Optimizer in our ASP.NET Web Application and some of the code is supposed to go in very specific places on certain pages. For example, for the "Control Page" Google has some Javascript that sits outside of the <html> tags.
I know I probably don't need to place the code exactly where Google recommends, but we've been getting some goofy results lately, and I really wanted to make it as watertight as possible to ensure it's not just bad implementation.
We have a lot of files in our project that reference the site.master, but only one needs to have some Javascript placed outside the <html> tag.
This, in theory, seems simple enough, my question is this: Do I need to put a ContentPlaceHolder in every file that references the site.master? (Even the tens that aren't passing any code to the site.master?) That's not something I feel like doing for many different reasons (altering tens of files). If that's the case, and I do need to add empty ContectPlaceHolders to every page, is there some other way around things without having to piece together a unique file just to put some Javascript outside of the <html> tag?
Thanks for any help.

The answer is no, as long as the ContentPlaceHolder in the Master is empty. That way, you only put Content for that ContentPlaceHolder on the pages where you want something rendered.

The simple question is that you not need to place Blank pace holder.
If the master page find this place holder, then its replace the content on it, if not finds it then its leave what have inside.

Related

Sharepoint Site Pages Readfile

I have been tasked with creating a small website using SharePoint 2010 Site Pages via SharePoint Designer. I am bringing over my favorite html template, which loads and runs as expected (mostly), but I quickly ran into the following problem.
I typically use PHP to inject certain data into my page by reading directly from a local file. I have no experience with ASP, which appears to be the only method to accomplish this. I have searched the docs and so many sites but haven't found a clear-cut way to do this, and now my head is spinning. Can anyone help me with a simple process for reading a file into the middle of my html file as it gets served?
For example:
<html>
<body>
Here's my title
<inject file contents here>
Here's my footer
</body>
</html>
Thanks all, any help will be much appreciated!
You cannot do this out of the box. You will have to create a customised solution to do this, by implementing a custom controls for instance.
When you start using Sharepoint you need to change your mindset about whatever you used before. Believe me you don't want to pick a fight with Sharepoint, because the beast will win.
back to your problem I think you should be looking at Reusable Content.
Here is a description about it:
http://en.share-gate.com/blog/sharepoint-reusable-content-a-forgotten-beauty
Basically you have a list where you manage all your reusable content bits (sort of like your files).
And then in the Rich text editor for the page content you can then insert a snippet that inject your reusable content.
if the content changes all the places you are using the reusable content bits will also change.
So this behaviour is pretty much the same you get if using a file. Except it's the SharePoint Way.
Good luck

Add a master page programmatically

First off, I know this isn't a normal thing to do, so if it isn't possible, just let me know.
I have a bunch of pages (100+) that are all designed to be contained within an iframe. Recently, I've decided to move away from this and use a master page to do some formatting on the page that used to contain the iframe. However, in order to do this, the page inside the frame is now going to be the page that is navigated to. What I need to be able to do is apply this new master page to a page that didn't have a master page prior and I'd like to do it without having to change the markup of all the other pages. All of these pages inherit from a single parent class that can be used to accomplish this, if it is possible. It is necessary that iframes are not used in this solution, as their compatibility is part of the problem I'm trying to work around. Thanks for any help/ideas you can offer.
EDIT
This is the error I'm getting when I try the way the comments suggest:
Content controls have to be top-level controls in a content page or a nested master page that references a master page.
Should be very possible. As I recall, you can just have your base class set its own MasterPage in the OnPreInit event:
this.MasterPage = "~/SpecificMasterPage.aspx";
Response to comments
That complicates things. Here's something you can try, but I don't know whether it will work: try creating regular page to be your "master" page, and loading the other pages in as if they were controls using the Page.LoadControl method. I don't know whether whole pages can be loaded this way, and even if they are this is hacky at best, since you'll be producing new <html>, <head>, and <body> tags within the body of the page.
So your best bet is probably to convert all your pages to either use a MasterPage or to be Controls. If you're clever, you might be able to write a little program that can do this to all your pages automatically.

ASP.NET website structure / flow

ASP.NET, web form model.
Is there any sample code/site that demonstrate a couple samples for regular website patterns/ templates? Like if I want to use tab to switch between different pages, should I put the code in a single page or in different page, and treat each tab as a page.
Or if in a search page (just a single search bar and button), should I display my result panel in same page using dynamically enable the result panel, or just to another page?
I want to find a general design pattern/ template. Please advise, thanks.
I don't know if this answer will be helpful to you or not. Correct me if I am wrong.
You are specifying demonstration about web designing. It seems the functionality you want is clearly saying to choose from weather you want to use AJAX or not. I suggest why don't you use jQuery Framework for all this functionality.
I would give this a read and consider what best fits your application and your programming style, no one size fits all with paterns.
http://msdn.microsoft.com/en-us/magazine/dd252940.aspx
After you have a general idea, head over to google.com and look for the patterns that catch your eye for simple tutorials
Edit:
For the specific question about whether you should modularize your code. The answer is almost always yes. If you think there is a chance that the component will be used somewhere else then doing this a head of time can save you a lot of headache later. This practice also makes maintaining a lot easier because it gives a clear scope of what could be causing a bug. Instead of having to look threw an entire page of unrelated code for things changing state unexpectedly in the page life cycle.

VS2008 Complains about css class names it should know about

I've seen this in a webcast somewhere, but I can't remember where, and all searching terms I'm trying are coming up unhelpful.
I've got a stylesheet for my site, and it's referenced in a master page. Child pages that use this master page use these styles, but .Net doesn't know about them. When the site is run, it all works great, but I'm trying to figure out how to get .Net to know about them at design time.
This should also fix the issue with not knowing about the javascript files I'm including, too -- I think it's all related and I can't for the life of me figure out how.
EDIT: I'm an idiot. This is the code that was being used to include the stylesheet.
<link href="<%= ResolveUrl("~/") %>css/styles.css" rel="stylesheet" type="text/css" />
I hate people who overthink things. Oh, and people who are too stupid to fully investigate an issue before they ask a question. Like me.
You can try using View->Manage Styles which brings up a list of the css that you can use in your pages at design time.
UPDATE: Actually how are you creating your child page? I just noticed that i have complete access to stylesheet classes that are referenced in master page.
I created child page as 'web content form' & then specified the master page. Then in my child page when i try to add cssclass to a label, it gives me a list of styles from the stylesheet referenced in master page.
I think it's just a limitation of Visual Studio's designer. It can't know all of the possible combinations of master pages/child pages, so it just seems to be a bit pessamistic at times. I wouldn't worry about it.

Problems with Server-side Includes

I desperately want to use server-side includes in a project I'm working on because I just have some HTML that repeats and I need to get it on several pages. Must I use ascx or some other include technology... I mean, will lightning strike if I use server-side includes?
My client -- the middle-person -- says "do what's easiest, this will probably be redone in a CMS soon anyway." Can I not use server-side includes?
It's ASP.NET 2.0.
Note: I feel this has been asked before, but I couldn't find it. If it has, please let me know and I will personally delete it, thanks!
Edit: Any way to get an include ON ONE LINE would be fine with me, if you have suggestions.
Edit: Why do I like includes?
Include code:
!--#include file="inc_footer.aspx"-->
the same code for a control. First you need one of these
<%# Register TagPrefix="a" TagName="HeyFooter" Src="inc_footer.ascx" %>
and then you can use it like this
<a:HeyFooter runat="server" />
this is kind of long for what I need.
Note Two security concerns with includes: 1) don't use the .inc extension, since it can be browsed. 2) do not include filenames based on user variables, as the best answer points o ut.
If you include a file via a string variable: <!--#include file=some_variable -->, then depending on how that variable is filled there are possible attacks a hacker could do to include his own files and run arbitrary code on your machine. But as long as you use a string literal, you won't run into this problem.
I would use Master Pages in ASP.NET. This is the accepted way to have common areas of a page.
You would create a Master Page similarly as you would regular pages, then modification of each of the other pages would be minimal. Add a single line to the top of each page file, then specify the sections used.
No, you most definitely do not need to use fancy .NET web form ways of doing this, if you want to keep it simple. Just put this at the points where you want it inserted:
<!--#include virtual="../repeatStuff/fun.html" -->
The html will show up there. I gave a path one up and down another directory. This is "easiest", but also has the virtue of being very straightforward. Note that this won't show up in your visual designer. (I never use it anyway.)
I still use includes every once in awhile for exactly the purpose you describe.
You don't really need to register a user control because it's just plain html anyway. And you don't want a master page because it's really just a snippet of html that needs to be on a few select pages.
So I've got includes like this from a glossary of help text files:
<!--#include file="~/Glossary/BusinessDetails.inc"-->
In my opinion there's nothing wrong with using old school include files for this purpose.

Resources