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
Similar Messages:
Jan 26, 2011
I have a multiline (> 50 lines) textbox containing plain text. I want to add either a session variable to the text in this box. In asp I would have done it by putting in <% %> code blocks but in .net I am getting the following error: "Code blocks are not supported in this context". I assume therefore that this would need doing in code behind.
Is there a quicker way than putting all the text from the textbox in a string in code-behind and then adding the variable on like this? I would like to keep the text in my aspx page if possible.
View 2 Replies
Oct 26, 2010
I've wrote the comprehensive post within my blog: [URL] In brief words everything is simple:
1. I've downloaded free Visual Studio C# 2010 Express and Visual Studio Web Developer 2010 Express
2. I've successfully installed these versions.
3. I've tried registration online - and got the appropriate keys which I've used for registration.
Finally all the keys I've got are not valid for the system - and after 30 days evaluation (for free version?) period all these products are not running anymore because all the keys I am providing from online registration are invalid.
View 2 Replies
Mar 25, 2011
I created a page that allows our customers to print their ads that they have listed with us. All of their image information is stored in our DB as a url since we run on multiple servers. In order to get the image on the page, I download it as a temporary file and than draw it on the page.
Code:
Dim Images As Generic.List(Of VehicleImages) = vInfo.VehicleImages
Dim picture As String = ""
If Images.Count > 0 Then
picture = Images(0).ImageURL
End If
If picture <> "" Then
Dim pic As String = picture.Replace(Session("imageDomain"), Session("imageShareName")).Replace("/", "")
writeToLog("Picture Location: " & pic) *Add to catch possible error, not part of the issue*
Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(pic)
Dim temppic As String = "*save path* emp_" & Date.Now.Ticks & ".jpeg"
img.Save(temppic)
System.IO.File.WriteAllText("D: emppdftester.txt", picture)
Dim imgNum As Int32 = pdf.AddImageFromFile(temppic, 0)
If imgNum = 0 Then
pdf.DrawText(LeftEdge, curY, "Couldn't load image")
curY += space + pdf.GetTextSize
Else
pdf.SelectImage(imgNum)
pdf.FitImage(LeftEdge, 180, 540, 260, 0, 0, 0)
curY += 200
End If
If System.IO.File.Exists(temppic) Then
System.IO.File.Delete(temppic)
End If
End If
The issue is that for one of our customers (not sure if there is more as noone has said anything), it errors on the bold line and the error is:
Quote:
Exception information:
Exception type: ArgumentException
Exception message: URI formats are not supported.
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
at System.IO.Path.GetFullPath(String path)
at System.Drawing.IntSecurity.UnsafeGetFullPath(String fileName)
at System.Drawing.IntSecurity.DemandReadFileIO(String fileName)
at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
at Dealers_Only_PrintVehicleAd.createPDFSelectable() in *filename*:line 213
at Dealers_Only_PrintVehicleAd.btnPrintAds_Click(Object sender, EventArgs e) in *filename*:line 46 *Line that calls the Sub*
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
View 4 Replies
Sep 28, 2010
where we use <%@ %> <%= %> <%# %> etc.
what else asp tags can be added in asp.net web pages?
View 2 Replies
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
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
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
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
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
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
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
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
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
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
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
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
Aug 13, 2010
Is it possible to share the claims based authentication of a logged in Sharepoint 2010 user with a separate Asp.net application?
The following article describes how it was done using Sharepoint 2007 and forms authentication through forms auth and sharing machine keys etc however I cannot find any information regarding the external application consuming the claims authentication that is now used in Sharepoint 2010?
View 2 Replies
Apr 16, 2010
I'm receiving this error on a page that previously worked fine, in fact the only change I've made to the page recently was to add another asp:TextBox and asp:RequiredFieldValidator control.
The page already had numerous ASP.NET controls on it, so I cannot see why these extra controls would make a difference, anyway I shall post the code below and hopefully you can see what the error is:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MeetingGenerator.ascx.cs"
Inherits="usercontrols_MeetingGenerator" %>[code]......
View 2 Replies
Dec 10, 2010
how to add grid view & ItemTemplate in code behind
[Code]....
View 2 Replies
Mar 18, 2010
I have a GridView inside of an UpdatePanel and the buttons for edit and delete into a templatefield
For the delete button, I also have a modalPopup extender and a confirmButtonExtender, due to the problem of the pannels flashing momentarily (and that is very ugly) I have created a css class with display:none
for the delete button I have created a javascript function called changeVisibility(id) to change the visibility
Here ir some code:
[Code]....
The problem is that when I execute the page, imagebutton onclientclick appears like this:
onClick=""
why is asp.net not processing correctly that, and, if you know another way to hide the panels before they flash on startup,
View 2 Replies
Nov 6, 2010
I have created an imageurl and label ids inside an itemtemplate which is inside a datalist but when I want to do some programming based off of those two ids, the code behind files do not recognize anything inside an item template.
Is there a way I can retrieve from an itemtemplate onto say like a string in a code behind file?
To make my explanation easier this is what I'm trying to do:
I have two div tags, one on the left and one on the right.
The div tag on the left contains a datalist of an Itemtemplate of various pictures.
When you click on one of these pictures, the same picture you clicked on will display in the right div but larger width and height.
View 3 Replies
Dec 15, 2010
How to find GridView ItemTemplate (Textbox) in Code behind
if we not know textboxid
View 2 Replies
Jul 9, 2010
Now I have a datalist
I have done the itemtemplate and edittemplate,when I click on the button in itemtemplate, the edittemplate will show.But that row in itemtemplate will disappear.How can I keep that row in itemtemplate and ecotent in edittemplate both appear?
View 4 Replies
Jul 29, 2010
I have two item template which consist two dropdownlist D1,D2...
here what im doing is d2 is binding based d1 selected value...
im using this code in D1_Selectedindexchanged
foreach (GridViewRow row in Gridview1.Rows)
View 21 Replies