Using Code Blocks In Head Content And Link Tags?

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


Similar Messages:

Custom Control Render JavaScript Code In Head Tags?

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

Why Does URLs Get Encoded In <link> Tags Within <head Runat="server"> And How To Avoid It

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

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

Server Removes Spacing Between Head Tags

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

Web Forms :: Remove Link In The Head Tag Of Html Page?

Jan 3, 2011

remove link in the head tag of html page

[Code]....

View 2 Replies

How To Add Title And Meta Tags For Content Pages In A Project Base On Master And Content Page

Oct 17, 2010

how can i add title and meta tags for content pages in a project base on master and content page(dinamically) ?

i used the blow method for master page :

[code]....

and the error is :(in line *)

Error 17 'System.Web.UI.MasterPage' does not contain a definition for 'SetMetaTags' and no extension method 'SetMetaTags' accepting a first argument of type 'System.Web.UI.MasterPage' could be found (are you missing a using directive or an assembly reference?)

View 3 Replies

Visual Studio :: Remove The <head></head> Tag From And All Information Contained In The Tag

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

How Embedded Code Blocks In WebPages

Sep 28, 2010

where we use <%@ %> <%= %> <%# %> etc.

what else asp tags can be added in asp.net web pages?

View 2 Replies

Resolve Code Blocks At Runtime (C#)?

Feb 3, 2011

I am writing a dynamic control that I want to pass in something along the lines of the following:

HyperLink myLink = new HyperLink();
myLink.NavigateUrl = "/Home.aspx?id=<%= DataBinder.Eval("PageId") %>";
myLink.Text = "The link";
myControl.Controls.Add(myLink);

I want to be able to resolve the myLink.NavigateUrl at run-time according to the context that myControl puts the control into in the end (this is not a WebControl and therefore adding to the collection of controls doesn't output to page).

View 2 Replies

C# - Code Blocks In Regular 4.0 Aspx Pages (not MVC)?

Mar 24, 2011

Is it possible to do something like this in regular ASP.NET (or something similar):

<ul>
<% foreach (var item in Model) { %>
<li id="<%: item.Id %>">
blah blah
</li>
<% } %>
</ul>

I need to do a gird, but I want to control how the html table is output.

View 3 Replies

How To Use If Statements With Razor And Inline Code Blocks

Jan 22, 2011

I'm updating my old .aspx views with the new Razore view engine. I have a bunch of places where I have code like this:

<span class="vote-up<%= puzzle.UserVote == VoteType.Up ? "-selected" : "" %>">Vote Up</span>

Ideally I'd like to do this:

<span class="vote-up@{puzzle.UserVote == VoteType.Up ? "-selected" : ""}">Vote Up</span>

However there's two problems here:

vote-up@{puzzle.UserVote .... is not treating the @ symbol as a start of a code block @puzzle.UserVote == VoteType.Up looks at the first part @puzzle.UserVote as if it's supposed to render the value of the variable.

View 1 Replies

The Controls Collection Cannot Be Modified Because The Control Contains Code Blocks

Mar 27, 2011

i saw few of solutions for this exception (like putting it in place holder, or replace the <% to <# ...etc) , but i don't get the idea about it, i mean what is the controls collection? and why it can't be modified if the added control contains code blocks?

View 2 Replies

C# - Controls Collection Cannot Be Modified Because The Control Contains Code Blocks?

Aug 11, 2010

I recently put some code <% %> code blocks in my Master Page. Note I've read of the "fix" for either moving things out of <head> or using <%# %> but neither of them work well for my application.

Now the weird thing is that I only get this error on one page of mine. All the other pages seem to work fine, so what actually causes this error? There is nothing I can think of that is unique about this page. It uses the script manager as does other working pages and there is just nothing extraordinary about this page. It does have quite a few custom controls on it, so hunting down what is different in this page is more difficult than usual.

So what actually causes the Controls collection cannot be modified because the control contains code blocks exception?

View 3 Replies

The Controls Collection Cannot Be Modified Because Control Contains Code Blocks

Dec 18, 2012

Error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

I have the following in my master file to load a dynamic seasonal background image:

HTML Code:
<style type="text/css">
body
{
background-image:url("<%=backgroundImage%>");
background-position: top center;
}
</style>

It works fine on most of my pages, but on one it throws the above error.

View 1 Replies

VS 2010 - ItemTemplate (Code Blocks Are Not Supported In This Context)

Nov 21, 2013

We are using Infragistics' WebDataGrid, but this question probably applies to all other grids. I am new to Infragistics (actually have worked with their controls years ago, but feeling new regardless!) and this application as well. So I'm looking to its existing code as a model.

I want to have a column called Tobacco with a Y or N value depending on if Smoker is true/false.

Ideally, the whole thing would be something like this:

Code:
<ig:BoundDataField Header-Text="TobaccoUse" Key="Smoker">
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.Smoker") != DBNull.Value ? (DataBinder.Eval(Container, "DataItem.Smoker") == true ? "Y" : "N") : "N"%>
</ItemTemplate>

Because I want to check for a null first and when I know I don't have one, test the value.

But since I am getting an error on that I am trying to start simple and build it up. I am getting the same error on this:

Code:
<ig:BoundDataField Header-Text="TobaccoUse" Key="Smoker">
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.Smoker") == true ? "Y" : "N"%>
</ItemTemplate>

The error is: Code blocks are not supported in this context.

Why is this a code block and should it be something else? What is my context?

This is an example of a line that works:

Code:
<ig:TemplateDataField Header-Text="DOB" Key="DOB">
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.DOB") != DBNull.Value ? Convert.ToDateTime(DataBinder.Eval(Container, "DataItem.DOB")).ToShortDateString() : ""%>
</ItemTemplate>
</ig:TemplateDataField>

I don't know if I need a Convert.ToBoolean in there somewhere but I tried and it didn't work and at this point I am just guessing which will take a long time for me to get it right.

View 2 Replies

"<%=" Is Not Working Correctly Inside Head - Link Tag?

Dec 19, 2010

I have been trying to create dynamic path for my css files to allow statrup application regardless of application path. I have srtange behavious with <%=

[Code]....

I believe above should generate app path, but it looks <%= is ignored and the code on my webside looks like this

[Code]....

When I move <%=Request.ApplicationPath%> outside href attribute or move whole link tag to body it works fine

View 5 Replies

AJAX :: Controls Collection Cannot Be Modified Because Control Contains Code Blocks

May 7, 2015

I have web.confing file when adding  tag page for set theme

After running project i have this error:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

<pages theme="Theme" styleSheetTheme="Theme" clientIDMode="AutoID" />

View 1 Replies

AJAX :: Controls Collection Cannot Be Modified Because Control Contains Code Blocks?

Apr 27, 2016

I am getting http exception in of the method of class file (search.aspx.vb) like "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)",

I have tried placing Java script function in the body of Master page from header, whereas I just removed the Java script tag and its contents in search.aspx (as of its not required now). Still getting exception. 

I also know that if we have something like this <%= in Java script function we need to replace with <%#.  But I don’t have this kind of code in any function.

View 1 Replies

Web Forms :: Meta Tag - Controls Collection Cannot Be Modified Because Control Contains Code Blocks

Jun 9, 2012

I want use meta tag in my page that read keyword from database

I set this code in my product.aspx page 

protected void Page_Load(object sender, EventArgs e) {
SqlCommand _cmd = new SqlCommand("select Keyword1 + ',' + Keyword2 + ',' +Keyword3 from House_info where BehCode=1115", _cn);
_cn.Open();
SqlDataReader _dr = _cmd.ExecuteReader();
while (_dr.Read())

[Code] ....

It worked correctly and show my keywords from database and show it in my product.aspx metatag

I have two other page

index.aspx   and store.aspx  in index.aspx i have 1button and 1 TextBox when user type their BEHCODE(columns name in users table) in TextBox it go to store.aspx page and show that users information on store.aspx

Now i want set meta tag in store.aspx page and i want  fill store.aspx  meta tag from my users table in data base

 This is index.aspx

protected void ImageButton3_Click(object sender, ImageClickEventArgs e) {
string data = Server.UrlEncode(txtNumeric.Text);
SqlCommand _cmd = new SqlCommand("traidname", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Parameters.Add("@BehCode", data);

[Code] ....

Here when i run website this error occur

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

In this line

this.Page.Header.Controls.Add(htmlMeta);
 
I use this code too 

<script type="text/javascript">
        $("input[id$=btnButton]").live("click", function () {
            return confirm("Do you want to submit?");
        });
    </script>

But it didn't worked this problem just happen here when i used  meta tag code in  other page it worked correctly . Why this happen?

View 1 Replies

Inject Code Into Masterpage / Html Head From A User Control?

Jan 10, 2010

I am struggling with something that I guess should be standard practice really. I have a number of user controls that use some JQuery plugins. I do not really want to link to the extra CSS and JS files from my main masterpage as this would cause extra load to the user the first time they hit the site, (admittedly it would only be the once), so I was just putting them links into the top of the user control. Then I looked at my source HTML, not nice! Even worse for controls that repeat multiple times on a page.

So I was thinking is there a way of injecting them into the Head of the page when they are needed from the User Control. For that matter is there a way of doing it to the footer for JS stuff?

View 4 Replies

Web Forms :: Excel Export - Controls Collection Cannot Be Modified Because Control Contains Code Blocks

Jan 24, 2012

The code on one of my aspx pages is giving me this error:

I'm getting this on the code behind for export to excel on one of my pages.

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).It is referring to this line Me.GridView1.Parent.Controls.Add(frm)

I have this code in the aspx page.  I am using two gridviews.  I need to have this on the page any way I can fix the code so I can use that export to excel you created?

  <% If(Session("PendingClaims"))%>then display gridview1<%Else%>

Then display gridview2<% End If %>

View 1 Replies

AJAX :: Ajaxtoolkit Version 4 - Error 'The Controls Collection Cannot Be Modified Because The Control Contains Code Blocks"

Sep 23, 2010

I was working on an asp.net 3.5 website and used ajaxtoolkit in it and when I use it in my page it was registered as below

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

and it was working well even After I upgraded my wevbsite to .net version 4 but when I started a new website from scratch in vs2010 using .net4 when I use ajax toolkit in this new site it is registered as folowing

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

and when I run the page I get the error The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>) I don't Know what is the reason for this. I noticed another thing. in my old website I was using thckbox script by using the files common.js, jquery-1.3.2.js,jquery.thickbox.js and puting them in a Javascript folder ad then registering them in Script manager as following

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Javascript/jquery-1.3.2.js" />
<asp:ScriptReference Path="~/Javascript/jquery.thickbox.js" />
<asp:ScriptReference Path="~/Javascript/common.js" />
</Scripts>
</asp:ScriptManager>

this was working well also but in my new site the jquery file version was jquery-1.4.1.js but also I added the old version f the javascripts files in the built in Scripts folder that is created by default b the new site and followed the same way in registering them in the script managerchange the JavaScript folder to the built in folder Scripts

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery-1.3.2.js" />
<asp:ScriptReference Path="~/Scripts/jquery.thickbox.js" />
<asp:ScriptReference Path="~/Scripts/common.js" />
</Scripts>
</asp:ScriptManager>

but this doesn't work also in the new site I think that there is something diffirent in the 2 case which leads to this change in performance I wish your support and advice about how to solve this matter

View 4 Replies

MVC :: Content Not Rendering In Form Tags?

Jun 11, 2010

I'm using a jQuery modal form to gather some information about a user and then redirecting them to another view. However, my submit button will not fire because none of the content is rendering inside the form tags on the generated output.

Here is my code:

[Code]....

[Code]....

[Code]....

View 1 Replies

How To Organized Page Specific CSS Link Tags With Spark View Pages

Mar 12, 2010

I'm currently using ASP.NET MVC 2 and the spark view engine. The main master page (application.spark) contains all of the CSS link tags that need to be present for all pages (global stuff). However, I have some content pages that have page specific CSS tags and currently I'm just sticking the link tag in the body as something like:

<content name="MainContent">
<!-- page specific csss -->
<link rel="stylesheet" href="/Content/css/page_specific.css" />

My problem is that when the page renders, this tag ends up in the which is not where it needs to be. Is there a solution for this?

I had was to check the controller in the Application.spark page and write out which page specific css file is required for that particular controller, however, that solution doesn't seem to scale well and I would imagine there is some way of creating the link in the child page and having it render where it's supposed to by the browser.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved