Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 4 of 4

Thread: Setting a static title

  1. #1
    omairkha is offline Member
    Join Date
    Aug 2011
    Posts
    89

    Question Setting a static title

    Hi,

    I have a static page (ie. not a topic, category, or product) and I would like to set the title for that page manually from within the .aspx, instead of having it dynamically populated. The page uses my template.master as the layout template.

    I cannot seem to figure out how or where to do this.

    Any suggestions are much appreciated.

    Thanks in advance for the help!

  2. #2
    omairkha is offline Member
    Join Date
    Aug 2011
    Posts
    89

    Red face

    Answering my own question...

    I was able to do this pretty easily using JavaScript.

    At the end of the page (before the </asp:Content>) you can use the following code:

    Code:
    <script language="javascript">
    	document.title = "the title you want";
    </script>
    In my particular case, I wanted to set the page title to that of an iframe that is displayed on the page. You can do that like so:

    Code:
    <script language="javascript">
         document.getElementsByName('iFrameID')[0].onload = function(){
    	document.title = window.frames.newswindow.document.title;
         };
    </script>
    Thought this might be useful to someone in the future...

  3. #3
    omairkha is offline Member
    Join Date
    Aug 2011
    Posts
    89

    Angry

    ok.. so the javascript method is only a visual solution... ie. it does not actually change the title, but displays the new title in the browser...

    this means that the actual page still has the original title so that when you use sharing buttons (ie. facebook share) it is pulling the title stored in the html, not the one overwritten by the javascript.

    any suggestions on how to fix this?

  4. #4
    omairkha is offline Member
    Join Date
    Aug 2011
    Posts
    89

    Default

    ok, so I was able to figure out how to do it in ASP.NET C#.


    In your myPage.aspx.cs file, set the very last line of function Page_Load() like so:

    Code:
    protected void Page_Load(object sender, System.EventArgs e)
    {
    
         <.....other existing code....>
     
    				
       //set page title
       Page.Header.Title = "This will over-ride title from ASDNSF";
    							
    }

    If anyone needs to do what I was doing (set the page title to that of one included in an iframe), there is an ASP.NET work around I found that works pretty well using Screen Scraping.

    Note: this might only work for pages on the same domain, but I have not tried it with pulling a page from a different domain.

    First, in your myPage.aspx.cs file, make the following changes:

    Code:
    using System;
    using System.Web;
    using System.Web.UI;
    using AspDotNetStorefrontCore;
    
    namespace AspDotNetStorefront
    {
    	/// <summary>
    	/// Summary description for news.
    	/// </summary>
    	public partial class myPage : SkinBase
    	{
    		static string myTitle = "no title";
    		publlic static string myContent = "";
    
    		
    		protected void Page_Load(object sender, System.EventArgs e)
    		{
    				
    			<...other existing code...>
    		
        	
    			using (System.Net.WebClient client = new System.Net.WebClient())
     			{
      								
    								
    				//get page
    				myContent = client.DownloadString("http://www.somesite.com/anypage.php?q=" + Request.QueryString["q"]);
    				
    				//find title
    				myTitle = myContent.Substring(myContent.IndexOf("<title>")+7);
                			myTitle = myTitle.Substring(0, myTitle.IndexOf("</title>"));
    								
     			}
    			
    			
    			//set page title
    			Page.Header.Title = myTitle;
    			
    			
    	    	}
    	
    
    		
    		
    		
    	}
    	
    	
    	
    }
    Then in myPage.aspx, replace your <iframe> tag with the following:

    Code:
    <% Response.Write(myContent); %>

    Hope this helps someone in the future!
    Last edited by omairkha; 09-29-2011 at 06:07 PM.