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.
I've got a repeater on my asp.net (VB): <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("Question_Number") %>' /> <%#Eval("Question_Desc")%>
Now what I want to do is, check a value that I haven't used called "Question_Type" which could be = 1, 2 or 3 depending if it is multiple choice, short answer, etc. I have tried this:
<% if Eval("Question_type") = 1 then Response.Write(" <asp:RadioButton runat=""server"">test1</asp:RadioButton>") Response.Write(" <asp:RadioButton runat=""server"">test2</asp:RadioButton>") Response.Write(" <asp:RadioButton runat=""server"">test3</asp:RadioButton>") end if %>
and I get this error: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. HOW can I use this value in a if statement?
The @( ) syntax enables a code block to have multiple tokens. For example, we could re-write the above code to concatenate a string and the number together within a @( code ) block
This is the code i have used to get LocationID from database with MerchantID. I am getting an exception from Fill dataset part. The error is Error converting data type varchar to bigint.
public DataSet getLocationID(long MerchantID) { //long LOCID = null; try { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@merchantID",MerchantID) }; string strCommandText = "Select LocationID from Merchant_Location where MerchantID ='@merchantID' order by LocationID ASC"; Debug.WriteLine(strCommandText); DataSet pds = new DataSet(); SqlHelper.FillDataset(DbConnString, System.Data.CommandType.Text, strCommandText, pds, new string[] { "LocID" }, parameters); return pds; } catch (Exception ex) { //LogError("Error Occurred When Retrieving LocationID: " + MerchantID.ToString(), ex); return null; } }
etc., which is placed inside of an ItemTemplate inside of a TemplateColumn. In the CodeBehind page I will bind a value to the OrderXml field, which occasionally is NULL.
When I run it the italic attribute works on the second item, but not on the first. I'm guessing it doesn't work because it's being passed as a literal string and the html formatting is lost.
How can this be made to work?
The reason I ask is because in my project, the text for the list item is stored in a database and I want the ability to include formatting for the item at the database level.
Code: @Html.Raw("hello <i>world</i>")
However, I am not getting the result I need, so here is a bit more code....
Code: @helper addNodes(dcNode As DocumentContent) @<li id=@dcNode.Id> @dcNode.nodeTitle <--This results in "White Papers - <i>New</i>" @Html.Raw(dcNode.nodeTitle) <--The truncates the string at the tag and results in "White Papers -" @If dcNode.children.Count > 0 Then @For Each childNode As DocumentContent In dcNode.children.Values @<ul id=@dcNode.nodeTitle>@addNodes(childNode)</ul> Next End If </li> End Helper
This is a recursive helper that populates node for a jsTree and works fine, but the inline html is not working. Here is what the result looks like.
The text for each li is shown twice because I am showing it once without and once with HTML.RAW. Notice the "White Paper" item... the second text is truncate at the <i> tag.Why is this and how can I fix it?
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).
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:
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:
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?
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?
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:
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.
I have a page with a Textbox, a Button and a Label control. On Button_Click event , I store the value of Textbox in a variable called S using code behind.
I want to show the value of S in the Lable control using inline code but not using the code behind. ?
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.
I'm using the 'Configure Data Source' wizard to connect to my database and show the dataset in Gridview. I want to be able to update, insert and delete entries but am unsure how to build the query. I can write simple update statments to change database entries but how can I do this for entries that have been changed within the gridview?
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
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?
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
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
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
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
I have a project made with inline code. How can I most quickly move inline code to codebehind for each webform? First, how can I add a codebehind page aspx.c or aspx.vb to one that doesn't have one?
Is it possible to do things in a PHPish way in ASP.Net? I've seen <%= %> but I've tried it and couldn't get it to work. The PHPish equivalent of what I want to do is