How To Set Head Tags In A Function In App_code
Mar 11, 2010
The below function has to be put within my common functions file in app_code folder. how do I do it?
It gives error like this:
Reference to a non-shared member requires an object reference
Public Sub setHeadTags(ByVal title As String, ByVal description As String, ByVal keywords As String)
Dim metaDescription As HtmlMeta = DirectCast(Page.Master.FindControl("metaDescription"), HtmlMeta)
Dim metaKeywords As HtmlMeta = DirectCast(Page.Master.FindControl("metaKeywords"), HtmlMeta)
metaDescription.Attributes.Add("content", "My big content description")
metaKeywords.Attributes.Add("content", "all, are, my, keywords")
Dim pageTitle As HtmlTitle = DirectCast(Page.Master.FindControl("pageTitle"), HtmlTitle)
pageTitle.Text = "Hey hey heY"
End Sub
View 2 Replies
Similar Messages:
Jun 11, 2010
I haven't been able to find relevant information through searches. I'm very green when it comes to sever side scripting. I have an ASPX page with a standard form. In the head I have meta tags, the title tag, and a link tag neatly ordered on their own lines. However, when viewing the source code after publishing to the server, the spacing between the tags is removed and it looks quite messy. (There are also <style> and <script> tags that follow, but they remain unaffected.)
I realize this has no practical effect on the site itself (in an SEO sense or otherwise). My project manager shows the source code to our clients to educate them on meta tags and page titles. It would help if it wouldn't become jumbled like this. I wonder if this is a common issue and if it's possible to prevent through better coding practices. HTML as authored, with tags separated on their own lines:
HTML Code:
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Welcome to Lawn Care Waukesha - Cut My Lawn. Cut My Lawn - Lawn Care Services has offered quality lawn cutting, fertilizing, aerating, and much more at affordable pricing since 2002! We currently offer lawn care service to Waukesha, Brookfield, Pewaukee, Menomonee Falls, and surrounding communities." />
<meta name="keywords" content="lawn cutting, lawn mowing, lawn care, fertilizing, aeration, mulching, shrub trimming, lawn mowing, edging, pruning, mulching, weed control, waukesha, Brookfield, Pewaukee, menomonee falls" />
<title>Lawn Care Waukesha — Cut My Lawn, Lawn Care Service</title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
HTML after being processed by the sever, with all the tags running together:
HTML Code:
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="description" content="Welcome to Lawn Care Waukesha - Cut My Lawn. Cut My Lawn - Lawn Care Services has offered quality lawn cutting, fertilizing, aerating, and much more at affordable pricing since 2002! We currently offer lawn care service to Waukesha, Brookfield, Pewaukee, Menomonee Falls, and surrounding communities." /><meta name="keywords" content="lawn cutting, lawn mowing, lawn care, fertilizing, aeration, mulching, shrub trimming, lawn mowing, edging, pruning, mulching, weed control, waukesha, Brookfield, Pewaukee, menomonee falls" /><title>
Lawn Care Waukesha — Cut My Lawn, Lawn Care Service
</title><link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
I'm not sure it's relevant, but here's the script used to send the form (which I didn't write, by the way). It's the final tag inside the page head:
HTML Code:
<script type="" runat="server">
Protected Sub SubmitForm_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsValid Then Exit Sub
Dim SendResultsTo As String = "email"
Dim smtpMailServer As String = "smtp"
Dim smtpUsername As String = "email"
Dim MailSubject As String = "subject"
Try
Dim txtQ As TextBox = Me.FormContent.FindControl("TextBoxQ")
If txtQ IsNot Nothing Then
Dim ans As String = ViewState("hf1")
If ans.ToLower <> txtQ.Text.ToLower Or ans.ToUpper <> txtQ.Text.ToUpper Then
Me.CutMyLawnForm.ActiveViewIndex = 3.......................
View 5 Replies
Feb 1, 2010
I'm building an asp.net app using themes, and I've assigned a theme to the app using the web config.
I have a bookmark icon that I want to use for my page and it is located in the themes directory, but I am having trouble referencing the themes location from a link tag in my header.
First I tried putting a code block inside the link tags href element, which did not work. Instead all it did was html encode the <% characters and output it directly to the browser:
<link rel="shortcut icon" href="/App_Themes/<%=Page.Theme %>/images/bookmark.ico" type="image/x-icon" runat="server"/>
I am able to put a code block inside an element in an hr tag though, so I don't know why it won't work in a link tag:
<hr test="<%=Page.Theme %>"/>
Then I tried doing a Response.Write inside the head tag, but I got an error saying the Controls collection cannot be modified because the control contains code blocks:
<% Response.Write("<link rel="shortcut icon" href="/App_Themes/" + Page.Theme + "/images/bookmark.ico" type="image/x-icon"/>"); %>
I also tried it just with a string literal, and got the same error:
<%= "<link rel="shortcut icon" href="/App_Themes/" + Page.StyleSheetTheme + "/images/bookmark.ico" type="image/x-icon"/>" %>
Is there any way to reference something from the themes directory inside the link tag?
I'm trying to do this in both an ASP.NET 2 and an ASP.NET 2 MVC app.
View 3 Replies
Feb 3, 2011
I am creating a custom control and was wondering if it is possible to render any JavaScript in the head tags of the page it is placed on? I am thinking I would need to use the FindControl method, but am not sure what I need to bind to. I am thinking the page object? Let me know if I am thinking in the right direction or if there is another option.
My only concern with the above mentioned idea is that how do I render all my content while placing some code in the head tags?
View 2 Replies
Jan 4, 2011
(I have tested this with a vanilla asp.net site running from the webdev server and it is a problem here also):
I have the following markup in my .master file
[code]....
Clearly Asp.Net does something to encode the url. As it happens, I really need the head tag to be runat="server" and I would also like to be able to have "&" in link-urls within it is there some trick I can use to have my cake and eat it too?
View 2 Replies
May 11, 2010
I have this import function which can be changed by the client in his desired way.Now I want to code such that if the client tries to import his own data on the page and doesnot give the tags in the order mentioned below his import function should be stopped.
It shouldn't make any changes unless the tags are in the right format because the problem now is if the tags are not in the right format when client changes then its importing over the existing files and directing to an error page which I dont want it should simply stop the import function if they are nt in the order.the code for this function is below
[code]....
View 7 Replies
Mar 11, 2010
I have several hundred html files that I want to remove the <head></head> tag from and all information contained in the tag. I am fairly sure I can do this in Visual Studio using the Find and Replace In Files with REGEX.
View 5 Replies
Jun 26, 2010
i have created a aspx page with the script manager, update panels and so on. Now, when i use some jquery functions which are included inside the head tags, when the page is run, i find the script tags generated inside the body instead of the head tag. i'm using visual studio 2005 only.
View 2 Replies
Feb 24, 2011
I am building a forum and I want to use forum-style tags to let the users format their posts in a limited fashion.Currently I am using Regex to do this.As per this question:How to use C# regular expressions to emulate forum tags. The problem with this,is that the regex does not distinguish between nested tags.Here is a sample of how I implemented this method:
public static string MyExtensionMethod(this string text){return TransformTags(text);}
private static string TransformTags(string input)
{string regex = @"[([^=]+)[=x22']*(S*?)['x22]*](.+?)[/(1)]";
MatchCollection matches = new Regex(regex).Matches(input);
for (int i = 0; i < matches.Count; i++)
var tag = matches[i].Groups[1].Value;
var optionalValue = matches[i].Groups[2].Value;
var content = matches[i].Groups[3].Value;
Now,if I submit something like [quote] This user posted [quote] blah [/quote] [/quote] it does not properly detect the nested quote.Instead it takes the first opening quote tag and puts it with the first closing quote tag.Do you guys recommend any solutions?Can the regex be modified to grab nested tags?Maybe I shouldn't use regex for this?
View 3 Replies
Feb 1, 2011
Is there a way to apply your own CSS tags to <li> tags when using ASP .NET 4.0 menu control? For example, say I have an external style sheet that has tags "class1", "class2", "class3", and etc. I want to apply "class1" to the first menu item. Then if menu item is selected, I want to apply "class2" and if it's not selected, "class3". I played with various 'Static' styles, but just can't get it work. I finally gave up and created my own menu control that extends ASP .NET menu control and provides my own custom rendering. This works, but I'm wondering if there is a way to get it work with built-in menu control.
View 1 Replies
Mar 8, 2011
I want regex operation for removing style tags,css,scripts and html tags from html to plain text in asp.net c#...
View 1 Replies
Jan 18, 2010
In a section in the <head> tags of my document I have code that lets me use the Id of my asp.net control from JavaScript like this:
<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>
However, if I want to modify the page structure in later stages of the page life cycle, it give me an error because I have the ASP tags in there. A work-around is enclosing the ASP tags in a server control like this:
<div id="customerIdContainer" runat="server">
<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>
</div>
But then I get a warning that a div tag is not allowed in the head tag. So is there a container tag that is valid in the head that I can add runat="server" to to make it a server control so I can workaround this problem without the warnings?
View 2 Replies
Jul 21, 2010
I've seen the <script type="text/C#> with intellisense.
If it is possible to script client side scripts in C#, some infomation or reference on how to do it. For example, do I need using statements, is the script compiled on the server.. etc.
View 5 Replies
Nov 7, 2010
I'm gonna use JQuery files in my custom ServerControl , thus I have to add below line within Head tag.
<script type="text/javascript" src="jquery-1.4.3.min.js"></script>
How can I do it in ServerControl with C#
View 1 Replies
Jan 31, 2011
How can I remove all html tags and script tags? consider also short tags like unclosed tags
<script>blah...</script>
<body> aaa<b>bbb</body>
This should return aaa bbb.
notice that all the contents inside the script tag is ignored.
View 3 Replies
Mar 27, 2010
i'm doing ajax website using PostWebRequest() function, when i call any .aspx page to the target html element the output is coming fine in IE but in FF(FireFox) is coming in html format(html tags) IE output : [URL] FF output : [URL]
javascript functions :
function PostWebRequest(postPage, HTMLTarget, parameter) {
displayElement = $get(HTMLTarget);
displayElement.innerHTML = "<div style='text-align:center;'><br /><br /><br /><br /><br /><img src='images/ajax-loader.gif' algin='center' /></div>";
var wRequest = new Sys.Net.WebRequest();
wRequest.set_url(postPage);
wRequest.set_httpVerb("POST");
var body = parameter;
wRequest.set_body(body);
wRequest.get_headers()["Content-Length"] = body.length;
wRequest.add_completed(onWebRequestCompleted);
wRequest.invoke();
}
function onWebRequestCompleted(executor, eventArgs) {
if (executor.get_responseAvailable()) {
if (document.all) {
displayElement.innerHTML = executor.get_responseData();
}
else {
displayElement.textContent = executor.get_responseData();
}
}
else {
if (executor.get_timeOut()) {
alert("Timed Out");
}
else {
if (executor.get_aborted())
alert("Aborted");
}
}
}
View 1 Replies
Feb 2, 2011
I'm having a bit of trouble trying to get this to work right:
[Code]....
View 1 Replies
Jul 28, 2010
I'm currently trying to setup testing with Selenium. It seems that Selenium sends a HEAD request to my route /Home/Index before it sends the GET request. This causes all my tests to fail. I was wondering how I would go about getting HEAD requests to respond correctly (not 404).
View 3 Replies
Aug 20, 2010
I just upgraded to VS2010 if that matters. I'm learning JQuery and noticed that scripts don't work if they're in the head tag. Also, I need the script tag with type="text/javascript" in the head (with nothing else) in order for the JQuery scripts in the body to work.
With a separate script tag in the <body> with my JQuery script, this works
[Code]....
View 6 Replies
Aug 11, 2010
I have seen on various websites how developers version their css/javascripts files by specifying querystrings similar to:
<head>
<link rel="stylesheet" href="css/style.css?v=1">
<script src="js/helper.js?v=1">
</head>
How is that done? Is it a good practice? I've been searching around but apparently, I'm not looking for the right terms. If it matters, I'm using ASP.NET.Edit:: I just noticed (via Firebug) that if I "version" my files (?v=1) they will always be loading and will always override the cache. Is there a way around that?
View 3 Replies
Jul 29, 2010
I'm successfully using a masterpage for all my .aspx's... the below is typical... where though can I place script such as this into my .aspx below since I don't really use a head/body?:
[code]....
View 5 Replies
Aug 18, 2010
I've never had to dynamically change the head of a webpage before and can't quite seem to get it. As mentioned in the title, the webpage is the child of a very simple master page. Here's what i've got:
[Code]....
I've tried :
Ctype(Me.Header.FindControl("head"), ContentPlaceHolder).InnerHtml
+= "<script type = 'text/javascript' src='" & Me.Master.get_root_rel() & "Sections/SectionJSFiles/EditFunctions.js' /></script>"
as well as
Me.Master.Head.InnerHtml += (same as above)
View 2 Replies
Mar 1, 2011
PHP experience (which meaby is causing this problem) and Iam having small problem passing data from codebehind to view-source.
I declared string variable on codebehind side such as:
...
public string mystring = "Scotty";
protected void Page_Load(object sender, EventArgs e)
{
...
So now I want to use it in view-code but when I put it in angle brackets (<%: or <%=) and put it in head element I got no access to this value. On the other hand when I put it in BODY element everything is ok.
My failing example (simplified):
<head runat="server">
<script language="javascript">
function beamMeUp()
{
alert(<%=mystring;%>);
}
</script>
</head>
<body>
<input type="button" onclick="javascript:beamMeUp" value="Warp6" />
</body>
why I can't use it (the <%=mystring;%>) in HEAD but i can use it in BODY ?
View 3 Replies
Oct 8, 2010
[Code]....
set the width of the datagrid and hidden the head?
View 1 Replies
Jan 3, 2011
remove link in the head tag of html page
[Code]....
View 2 Replies