Results 1 to 6 of 6

Thread: dynamically change keywords and title

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870

    dynamically change keywords and title

    is it possible to change the keywords and title of a webform in code?

    Many thanks
    Nick
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Sure, do something like:
    Code:
    <title><%# strMyTitle %></title>
    Declare the strMyTitle string variable as public, then set it in code. When the page is rendered, the contents of the variable will be written inside the title tag.

    Do the same concept with anything else on the page.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    Thanks!
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    well i've tried it and it doesn't work but i expect i've done something stupid.

    I've declared strTitle as public at the top of the forms code, and in the form_load event set it. Then set it in the <title> tag in the html but it doesn't work.

    Am i setting it in the wrong event?

    Thanks
    nick
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  5. #5
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Took me a while but I've found a LiteralControl method which you can use for this:
    Code:
    Dim strWinTitleText as string = "New Window Title"
    Me.Controls.Add(New LiteralControl("<title>" & _
    strWinTitleText  & "</title>"))

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  6. #6
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    In the code hellswraith posted, change the pound sign to an equals so it looks like this:
    Code:
    <title><%= strMyTitle %></title>
    here's a working example:
    PHP Code:
    <script language="C#" runat="server">
    private 
    string _pageTitle "";
    public 
    string PageTitle
    {
        
    get
        
    {
            return 
    _pageTitle;
        }
    }
    protected 
    override void OnLoad(System.EventArgs e)
    {
        
    _pageTitle "My Page Title";    
    }
    </
    script>
    <
    html>
        <
    head>
            <
    title><%= PageTitle %></title>
        </
    head>
    </
    html
    or you could do something like this:
    PHP Code:
    <script language="C#" runat="server">
    protected 
    override void OnLoad(System.EventArgs e)
    {
        
    PageTitle.InnerText "My Page Title";
    }
    </
    script>
    <
    html>
        <
    head>
            <
    title id="PageTitle" runat="server"/>
        </
    head>
    </
    html
    or if you wanna use code behind:
    here's the html side of things:
    Code:
    <html>
    	<head>
    		<title id="PageTitle" runat="server"/>
    	</head>
    </html>
    and here's the code behind:
    PHP Code:
    public class Default : System.Web.UI.Page
    {
        protected 
    HtmlGenericControl PageTitle;        
        protected 
    override void OnInit(EventArgs e)
        {
            
    PageTitle.InnerText "My Page Title";
        }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width