I am using Ajax calendar in an ASP.NET application like below lines of codes
<asp:TextBox ID="txtDOB" placeholder="(mm/dd/yyyy)" runat="server" onchange="ValidateDate()">
</asp:TextBox>
<ajax:CalendarExtender ID="txtDOBCalendar" runat="server" Format="mm/dd/yyyy" TargetControlID="txtDOB">
</ajax:CalendarExtender>
It is not working. It throws error message like
"The Controls collection cannot be modified because the control
contains code blocks (i.e. <% ... %>)."
I guess there must be some code block <%= ...%>. Replace it with <%# ...%>. Hope it helps.
Related
I have a repeater in which i have a textbox with a regex validator. The code looks basicly like this:
<asp:Repeater ID="rptr" runat="server">
<ItemTemplate>
<div>
<!-- controlls -->
<asp:TextBox ID="tbText" runat="server" ClientIDMode = "Static" EnableViewState="true" OnTextChanged="tbText_TextChanged"></asp:TextBox>
<asp:RegularExpressionValidator ID="tbTextValidation" runat="server" Text="*" ToolTip="wrong!" ControlToValidate="tbText"
SetFocusOnError="false" ValidationExpression="^([a-zA-Z])$">
</asp:RegularExpressionValidator>
</div>
</ItemTemplate>
</asp:Repeater>
The problem I have is that when I add a wrong text in the first field of the repeater the error text appears on all textBoxes (even if the rest are correct)
If i add a correct text in first field and a wrong text in another field/fields, the error text appears only where it's supposed to(in the wrong fields).
So, my question is, what could cause this?
Please try after removing the ClientIDMode = "Static" from text box of the repeater
My code is like this
<asp:Repeater ID="rptEvaluationInfo" runat="server">
<ItemTemplate>
<asp:Label runat="server" Id="lblCampCode" Text="<%#Eval("CampCode") %>"></asp:Label>
</ItemTemplate>
Everything looks okay to me, But it generates an error in the runtime. When I remove this part
Text="<%#Eval("CampCode") %>"
error goes.
SO I assume the issue is with databind. So I tried an alternative like this
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<label><%#Eval("CampCode") %> </label>
</ItemTemplate>
And it also works good. Can any one tell me what is the issue with my first code?
Note: I don't have access to the error message due to the special
reasons on my project , that's why I have not posted it here.
And I want to use ASP controls itself on the case that's why i haven't
gone with my second solution
The problem is with quotes. Currently you have double quotes everywhere, so ASP.NET is not able to parse this. Change outer ones to single quotes like this:
Text='<%#Eval("CampCode") %>'
I am working on a web application. The process regarding the problem is that I am fetching users comments from DB using Entity Framework Model. I am using a listview to show Customers Name, Rating and Comments.
The problem is that I am using a Ajax toolkit control called HTMLEditor for storing comments in the DB, so when I have to display the comments, I need the same control ie HTML Editor. Now when I use the following code to create the ITEMTEMPLATE for the listview,
<ItemTemplate>
<tr style="background-color:#EDECB3;color: #000000;">
<td><%# Eval("CustomerName")%></td>
<td> <img src='Styles/Images/ReviewRating<%# Eval("Rating") %>.png' alt="">
<br />
</td>
<td> <cc1:Editor ID="Comments" runat="server" Text="<%#Eval("Comments") %>"/>
</td>
</tr>
</ItemTemplate>
Everything is working except the line
<td> <cc1:Editor ID="Comments" runat="server" Text="<%#Eval("Comments") %>"/>
</td>
It says that the server tag is not well formed. please help.
Updated Error: I added nounicode="true". and the error I encountered is
Could not find any resources appropriate for the specified culture or
the neutral culture. Make sure
"AjaxControlToolkit.Properties.Resources.NET4.resources" was correctly
embedded or linked into assembly "AjaxControlToolkit" at compile time,
or that all the satellite assemblies required are loadable and fully
signed.
you should try
<cc1:Editor ID="Comments" runat="server" Text="<%#Eval('Comments') %>"/>
the text proprty is not the same.
Try below code:
Text='<%#Eval("Comments") %>'
Using the ScriptManager on the page solve the problem.
As far as the problem of displaying HTML text in HTML Editor is concerned, I decided not to use the HTML Editor from Ajax Control Toolkit. Rather I displayed the html text raw on the page using the html decoding utility like this,
<%#Server.HtmlDecode(Eval("Comments").ToString()) %>
"rr_only4you" told that answer is correct, i got the error like use blow one
Text="<%#Eval("Comments") %>"
after that i change that to
Text='<%# Eval("Comments") %>'
this format it will correct,
you use this one
<cc1:Editor ID="Comments" runat="server"><%# Eval("Comments") %></cc1>
I'd like to change the text attribute of a button according to the session landuage. So I write:
<asp:Button id="btOptIn" runat="server"
Text="<% = UI.Instance.TxtSubmit %>"
onclick="btOptIn_Click" />
This does not work. I tried several other versions (like Text='<%# Eval(UI.Instance.TxtSubmit) %>') but could not succeed.
The same code (<% = UI.Instance.TxtSubmit %>) works outside the quotes of the attribute. What is the syntax to make it work within an attribute of a control?
Thank you for your time.
<asp:textbox id="tbName" runat="server" Text='<%# Eval("test") %>' />
<%= %> is a shortened response.Write() and is never valid as an attribute, for any server tag.
<%# %> can be used, only if the conatainer is databound (the page in your case).
<%$ > can be used to access data in resources files.
In the Page_Load of you will have to make a call to Page.DataBind() for this to work.
I have a Customer class with a string property comments and I am trying to bind it like this:
<asp:TextBox ID="txtComments"
runat="server"
TextMode="MultiLine" Text=<%=customer.Comments %>>
</asp:TextBox>
However, it gives me the error:
Server tags cannot contain <% ... %> constructs.
I also have a method in the class called GetCreatedDate and in the aspx page, I am doing
<%=GetCreatedDate()%> and <%GetCreatedDate();%>. What is the difference?
Alternatively you can set the value in the Page_Load event of the code behind file:
txtComments.Text = customer.Comments;
you should use "<%# %>" for data binding
<asp:TextBox ID="txtComments"
runat="server"
TextMode="MultiLine" Text="<%# customer.Comments %>">
</asp:TextBox>
Try this instead.
<asp:TextBox ID="txtComments"
runat="server"
TextMode="MultiLine" Text=<%# customer.Comments %>>
</asp:TextBox>
Notice the = to #
Use the DataBinding syntax as stated, <%# customer.Comments %>. This syntax is only evaluated when the TextBox is databound. You would usually use it in a DataBound list. In this case you need to databind the control manually. Override the page's OnDataBinding method and call txtComments.DataBind();
The databinding syntax is the only way to declaratively set ServerControl properties from the aspx page. The Response.Write of the other syntax happens at a time that the ServerControl properties cannot be accessed. If the control is not inside a databound control, you have to databind it.
If you were looking to go all declarative in your page, you don't gain to much using this method because you still need to write code in the code behind.
An alternative if you want to use the TextBox on its own without a parent DataBound control would be to subclass the TextBox, add an AutoBind property, and in the subclassed control call its DataBind method if it is true. That would let you bind the values without writing databinding code in the code behind.
You could also add the TextBox and other form controls to a FormView control and bind it to your object. You can still use the DataBinding syntax in that case.
try this
<asp:TextBox ID="txtComments"
runat="server"
TextMode="MultiLine" Text='<%# customer.Comments %>'>
</asp:TextBox>