0

Example usage

code behind definition

public string srTitle = "";
public string srDescription = "";
public string srKeywords = "";

aspx page usage

  <title><%=srTitle %></title>  
  <meta name="keywords" content="<%=srKeywords %>" />
  <meta name="description" content="<%=srDescription %>" />

Is this usage correct ? Are there any other better, effective or etc way?

Thank you

asp.net 4 , C#

2 Answers 2

1

That method does work, though if you can, you would be better off setting these values in the code-behind; it will help keep your ASPX clean.

You can add meta data like:

HtmlMeta meta = new HtmlMeta();
meta.Name = "keywords";
meta.Content = srKeywords;
this.Header.Controls.Add(meta);

meta = new HtmlMeta();
meta.Name = "Description";
meta.Content = srDescription;
this.Header.Controls.Add(meta);

And page title:

Page.Title = stTitle;
Sign up to request clarification or add additional context in comments.

6 Comments

thanks. this looks better way. but for assigning variables inside html the way i showed is correct right ?
Yes, what you showed works fine. If you want, you could change Public to Protected then it can only be accessed by code in that page.
how can other pages access that variable ? would this change make any performance problem ?
There would be nothing from stopping you creating an instance of that page elsewhere to get to its public properties and methods. Setting it to Private will mean any code creating an instance of it won't be able to directly access it.
thanks for answers. i never did such thing so don't know. i am the only coder so far (3 years) :)
|
1

that's fine.

Another way would be through code-behind :

http://www.high-flying.co.uk/c-sharp/Dynamic-META-Tags.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.