AJAX Toolkit and Listview - c#

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>

Related

Issue while using ajax calendar

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.

How I can see a Image in my ImageButton?

I write a ASP.NET Application for creating a signatur and other stuff. And I use the AjaxToolkit with the CalenderExtender. I want if I click on a ImageButton that open the extender and the TextBox get the Data. It works fine but I don't see the ButtonImage :( >.<
Where I can get a Image for my ImageButton and how it works? Here my ASPX Site Code
...
<tr>
<td>Abwesenheit von: </td><td>
<asp:TextBox ID="txtAbwesenheitVon" runat="server" Enabled="false"></asp:TextBox>
<asp:ImageButton ID="imgbtnAbwesenheitVon" runat="server" ToolTip="Abwesenheit von..." PostBackUrl="~/App_Theme/Calender.ico" />
<asp:CalendarExtender ID="AbwesenheitVon" runat="server" TargetControlID="txtAbwesenheitVon"
Format="dd.MM.yyyy" PopupButtonID="imgbtnAbwesenheitVon"></asp:CalendarExtender>
</td>
</tr>
...
My second Question is.
Can I use a Label for the textBox, too?
But I see only this..._->
Replace
PostBackUrl="~/App_Theme/Calender.ico"
with
ImageUrl = "~/App_Theme/Calender.ico"
Image.ImageUrl Property
Use ImageUrl property instead of PostBackUrl

Add a download Hyperlink in gridview in visual studios 2010

My problem is simple, I would like to make the last column of my gridview to be a download link to a file in local on my computer.
I have my datatable with 3 columns :
User_id, request_id, FilePath
FilePath is the path (string) to the file on my computer, what I've been trying is :
In my gridview on the webpage display the 2 first columns (User_id and request_id).
On the 3rd column I added a hyperlink field and tried to link it (with the property DataNavigateUrlField) to the content of the column FilePath.
I've ended up with dead links on which i can't even click, they just change color on mouseover.
Any one have a clue about that ? Thanks a lot
A possible solution could be to use a TemplateField for your Hyperlink column:
<asp:GridView AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href='<%# DataBinder.Eval(Container.DataItem, "FilePath") %>'>
<%# DataBinder.Eval(Container.DataItem, "FilePath")%>
</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
will create the desired output:
<tr>
<td>
<a href='c:/directory/file.xxx'>c:/directory/file.xxx</a>
</td>
</tr>
It seems that a HyperLinkField does not accept a file path for its DataNavigateUrlFieldsproperty.
I tried to outsmart it by setting the DataNavigateUrlFormatString property:
<asp:HyperLinkField DataNavigateUrlFormatString="file:///{0}" DataNavigateUrlFields="FilePath" DataTextField="FilePath" />
but the issue remains and will only produce
<tr>
<td>
<a>c:/directory/file.xxx</a>
</td>
</tr>
try to use this
WebClient.DownloadFile(Uri,String)
And read this how to get needed event hyperlink

c# code in control attribute in aspx file

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.

Show image from sql on non javascript link

Hi say of have a table of cars in my SQL database. That table has a column for the car make and a column called picture of type:
Picture(image, null)
I'm then displaying my cars in a repeater and so it might look like this:
<asp:Repeater id="carsRepeater" runat="server" DataSourceID="CarsDataSource>
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label id="carMakeLabel" runat="Server" Text='<%# Eval("Make") %>' />
</td>
<td>
Some how display a clickable image here
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</Footer>
</asp:Repeater>
What I'm wanting is in column two to get the picture of the car to display and make it so you can click on that picture and it will run a method in the code behind. Also I have this requirement where the picture click method mustn't require javascript to run.
Can someone please give me an idea of how I would go about this?
I'm currently thinking about putting the image somehow in a link but I'm not sure how to display the image. Maybe the asp:Image but that requires an ImageUrl.
Try image button, it displays an image, doesn't require javascript and you can run a method on click event from code behind
Write an HTTPHandler (say CarImage.ashx) and in that handler, given ID of the image return the binary data with ContentType of image/gif (or whatever). Render an image tag in the datagrid with src as CarImage.ashx?ImageID=xxxxx. The process is described many place including this one.

Categories