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


Similar Messages:

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

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

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

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

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

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

Multiline Textbox - "Code Blocks Are Not Supported In This Context"

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

Error Message, "The Controls Collection Cannot Be Modified Because The Control Contains Code Blocks"

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

Code Behind Not Found At Runtime?

Jan 30, 2011

I've an ASP.NET application running fine locally, I've published the site and copied all files up to the live server and all is not good.99% of the pages are doing just as they should be, but just two pages are complaining that they can't find the code behind file? This is kind of urgent (demo tomorrow), so any help appreciated. Error message below...

Parser Error Message: The file
'/CompanyRoot/_ReactiveTaskManagement/ReactiveTaskPage/ReactiveTaskEdit.aspx.cs'
does not exist.

[code]...

View 1 Replies

Localization :: How To Set The Culture Programmatically Via Code Behind At Runtime

Jul 13, 2010

I want to have my web site localized to 3 languages english, spanish, french.

Is it possible by clicking the flags on the home page set the globalization culture tweak, in flag image click?

View 2 Replies

Web Forms :: Close Page In Code On Runtime?

Feb 25, 2011

How can i Close page in my code on runtime

View 9 Replies

Web Forms :: Changing Title O Sitemapnode At Runtime From Code Behind C#

Aug 15, 2010

I have a site map on my project and I have section which get values from sql database and it changes according to querystring Id value. In my sitemap the title of the page is everytime same. but I want tpo change it at runtime. I am using multiple sitemaps and My sitemap is not the default one. its name is rootSitemap. I tried some code which I got from msdn but it seems doesn't work for me;

[Code]....

Here is my sitemappath code which is situated in my master page;

<asp:SiteMapPath SiteMapProvider="rootSitemap" ID="SiteMapPath1" runat="server"></asp:SiteMapPath>

View 23 Replies

C# - Microsoft JScript Runtime Error: Object Expected After Using Code

Aug 4, 2010

i am getting this error when the below condition match, i am using the below code in Content page and in my master page i have this

<asp:ScriptManager EnablePartialRendering="true" EnablePageMethods="true" ID="smgr" runat="server" />

Error: Microsoft JScript runtime error: Object expected

if (lstRecipient.Items[i].Text == ddlRecipient.SelectedItem.Text)
{
lstRecipient.Items.RemoveAt(i);
isDuplicate = true;
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertAdd", "jAlert('Recipient name is already in the list.', 'Duplicate Entry!');", true);
}

View 1 Replies

Resolve URL In Bound Data

Mar 17, 2011

i want to show a menu in some pages.

the menu is build from db with repeater

[code]....

when i am in "folder/page1.aspx" all the link are ok [URL]. when i'm in a folder "folder/folder2/page1.aspx" the links are [URL]

UPDATED:

i change it to

<a href="<%# VirtualPathUtility.ToAbsolute("~/admin/"+(string)Eval("TD_PageName"))%>"><%# Eval("TD_Name")%></a>

View 2 Replies

How To Resolve Conflicting Assemblies In C#

Jun 15, 2010

In my web application I am using NHibernate.dll. This has a dependency on folowing assembly.

'Antlr3.Runtime, Version=3.1.0.39271,
Culture=neutral,
PublicKeyToken=3a9cab8f8d22bfb7'

Now in the same project for another requirement I have to introduce Antlr3.StringTemplate.dll. Which has a dependency on another version of the above assembly.

If I use the version of Antlr3.Runtime.dll which satisfies NHibernate , Antlr3.StringTemplate starts complaining and vice-versa.

View 4 Replies

Trying To Get Into TDD But Hitting Some Stumbling Blocks?

Jan 5, 2011

I've been trying to get into TDD but am hitting some stumbling blocks. I suppose a simplified example would be the best way to explain. My first assumption is that I start from the top. I want a web page that displays a list of categories say. So I write a test for a CategoryController whose Index action should return this list:-

Code:

[code]....

Bingo our test will pass. Now my problem here is how does TDD drive us beyond this point? Our tests have passed and it fulfills out requirements but of course we know that a fully working app would need say an ICategoryService to be passed into the Controller and the controller would use this to retrieve the categories.

View 10 Replies

Resolve Url In Facade Or Controller Class

Jan 28, 2010

I have a facade class that my controller class calls out to and in that facade class, for whatever reason, I'm building a string a href element. And it resolves fine in casini but when it gets out in the real world like localhost it doesn't work. Is there a way to do this?

string goBackLinkForErrorMessage = "<br /><a href='/MyController/Action?id=" + blah + "'>Go Back</a>";

View 1 Replies







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