Making an email label a hyperlink - c#

I was wondering if it is possible to make a label a hyperlink? Below is the code for a column I have set up and I want to make "lblEmail" clickable so that the email opens up and with that email address in it. The idea is that as various users log in to the site, their unique info will appear in the column. Is it as simple as wrapping the label control in an anchor tag? If so, I must be missing something because I tried that. Since I am new, it is likely I missed something!
Thanks in advance!
<p>
<asp:Label ID="lblName" runat="server" Text=""></asp:Label> <br />
<asp:Label ID="lblPhoneNo" runat="server" Text=""></asp:Label> <br />
<asp:Label ID="lblAddress" runat="server" Text=""></asp:Label> <br />
<asp:Label ID="lblCity" runat="server" Text=""></asp:Label>, <asp:Label ID="lblState" runat="server" Text="Label"></asp:Label> <asp:Label ID="lblZipCode" runat="server" Text="Label"></asp:Label> <br />
<asp:Label ID="lblEmail" runat="server" Text=""></asp:Label> <br />
</p>

Instead of using a label, you could make use of an hyperlink control.
The usage is as follows:
<asp:HyperLink id="hyperlink1"
ImageUrl="images/pict.jpg"
NavigateUrl="http://www.microsoft.com"
Text="Microsoft Official Site"
Target="_new"
runat="server"/>

Why not just use a hyperlink server control?
<asp:Hyperlink runat="server" id="lnk1">Your Text Here</asp:Hyperlink>
If you need additional formatting, you can wrap it in other another tag (or insert any legal HTML tag within the hyperlink).

Instead of using a label like hyperlink way, you should better use directly a hyperlink. Try the following :
<asp:Hyperlink runat="server" id="email" NavigateUrl="your_desired_address">
EmailLabelContent here
</asp:Hyperlink>
Thanks.

Related

Place RequiredFieldValidator inside a asp:DataList

I have a problem with placing RequiredFieldValidator into a DataList, and some assistance would be greatly appreciated.
Problem description:
When I place the <asp:RequiredFieldValidator>inside the <ItemTemplate> and run the page I get the following error page:
When I place it outside of it, the page works with no error, but obviously it cannot identify witch <asp:TextBox> does not have content in it, before it is posted back. And I would like to make where it is able to tell if a particular text box in the data list does not have text entered.
Here is the markup: (the Image src attribute is not implemented yet)
<asp:DataList ID="imageUploadRoster" runat="server"
DataSourceID="ImageUploadRosterDataSource" RepeatDirection="Horizontal" RepeatColumns="5" HorizontalAlign="Left">
<HeaderTemplate>
<h3>Set Image Names</h3>
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Height="180px" Width="180px" />
<ItemTemplate>
<div class="imageSetNameDiv">
<asp:HiddenField ID="ImageId" runat="server" Value='<%# Eval("ImageId") %>' />
<asp:HiddenField ID="ImageMimeTypeLabel" runat="server" Value='<%# Eval("ImageMimeType") %>' />
<asp:Image ID="ImageThumbnailLabel" runat="server" Src='<%# Eval("ImageThumbnail") %>' Width="120px" Height="120px" />
<br />
<asp:RequiredFieldValidator ID="imageNameRequired" runat="server"
ControlToValidate="ImageName" ErrorMessage="RequiredFieldValidator"
ValidationGroup="imageUploadValid">
</asp:RequiredFieldValidator>
<asp:TextBox ID="ImageName" runat="server" Text='<%# Eval("ImageName") %>' />
<br />
<hr />
<asp:Button ID="removeImage" runat="server" Text="Remove" CommandName="delete" CommandArgument='<%# Eval("ImageId") %>' />
</div>
</ItemTemplate>
</asp:DataList>
Thank you in advance for any assistance.
Peter
This error happens when ASP.NET encounters two controls with the same ID on the page. I guess for some reason in your case validators for each item get the same ID. Setting the following property:
ClientIDMode="Predictable"
for validator should fix it. This mode makes sure control in databound context gets correct ID.

DataList does not bind image

I am using Datalist and bind some information on it, but my Datalist is not showing my image.
Here is My Aspx Code:
<asp:DataList ID="datalistnewsrelease" runat="server" RepeatColumns="4" BorderColor="WhiteSmoke"
RepeatDirection="Vertical" RepeatLayout="Flow" Width="100%" OnItemCommand="datalistnews_ItemCommand">
<ItemTemplate>
<div class="newsbox m5">
<p class="black">
<asp:Label ID="lbldate" runat="server" class="b red" Text='<%#Eval("NewsReleaseDate") %>'></asp:Label>
<asp:Label ID="lblmonth" runat="server" class="b red" Text='<%#Eval("NesReleaseMonth") %>'></asp:Label>
<asp:Label ID="lblyear" runat="server" class="b red" Text='<%#Eval("NewsReleaseYear") %>'></asp:Label>
<br>
<asp:Label ID="lbltitle" runat="server" class="b blue" Text='<%#Eval("NewsReleaseTittle") %>'></asp:Label>
<a href="<%#Eval("NewsReleaseImage")%>" rel="gallery">
<img src="<%#Eval("NewsReleaseImage")%>" width="88" height="62" class="fr ml8" alt="">
</a>
<asp:ImageButton ID="NewsRelease" runat="server" Style="float: right;" img src="images/read.png"
CommandArgument='<%#Eval("NewReleaseId")%>' CommandName="View" />
</p>
<div class="cb pb5">
</div>
</div>
</ItemTemplate>
</asp:DataList>`
My code is similar to a Gridview I am binding the DataList to, but only that the image is not showing up.
Could you please share the value coming to "NewsReleaseImage" .
Is it plain image file name or relative path ? If it's plain file name then append relative your paths in ItemBound, if its fixed then you can append directly like below
src="/Images/<%#Eval("NewsReleaseImage")%>"
I suggest you to view the generated HTML and see the generated src attribute.

Programmatically scroll/move to an item in a .net asp:listview control

I have a web page that has an asp:ListView and I am trying to figure out how to programmatically scroll to a certain item. Here is my aspx markup:
<asp:ListView ID="lvGlossary" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="lvGlossary_ItemDataBound">
<LayoutTemplate>
<div class="glossaryTitle">Glossary</div>
<div id="ItemPlaceholder" runat="server"></div>
<br />
</LayoutTemplate>
<ItemTemplate>
<div class="glossaryEntry">
<span class="glossaryWord">
<asp:Label ID="lbWord" runat="server" Text='<%# Bind("Word") %>' />:
</span>
<span class="glossaryDefinition">
<asp:Label ID="lbDefinition" runat="server" Text='<%# Bind("Definition") %>' />
</span>
<br />
</div>
</ItemTemplate>
<AlternatingItemTemplate>
<div class="glossaryEntryAlternating">
<span class="glossaryWord">
<asp:Label ID="lbWord" runat="server" Text='<%# Bind("Word") %>' />:
</span>
<span class="glossaryDefinition">
<asp:Label ID="lbDefinition" runat="server" Text='<%# Bind("Definition") %>' />
</span>
<br />
</div>
</AlternatingItemTemplate>
</asp:ListView>
In my c# code behind I am populating a text box with text and when the user selects a word I want to automatically scroll to the word in the listview so it is visible. It most likely needs to be done client side, so I think I need some javascript to do this. Can anyone point me to an example of how to do this?
Any help is appreciated!!
Thank you
You could use an element's scrollIntoView javascript method:
document.getElementById('id').scrollIntoView(true);

Dynamic Id property on items in ListView

I am developing a simple message board in ASP.NET Web forms and I list all posts in a ListView controller. My code looks something like this:
<ItemTemplate>
<article class="post">
<div class="postinfo">
<div class="postauthor">
Author: <strong><%# Eval("Author") %></strong>
</div>
<div class="postdate">
Date: <strong><%# Eval("PostDate", "{0:D}") %></strong>
</div>
<div class="postvotes">
<asp:Button class="postupvote" id='up<%# Eval("Id") %>' runat="server" />
<asp:Label ID="postvotescount_<%# Eval("Id") %>" class="postvotescount" runat="server" Text="<%# Eval("Votes") %> votes"></asp:Label>
<asp:Button class="postdownvote" id='down<%# Eval("Id") %>' runat="server" />
</div>
</div>
<div class="postcontent"><%# Eval("Text") %></div>
</article>
</ItemTemplate>
My problem is the voting functionality. I want to have css id properties, containing the unique database id of the post. That way I will know the Id of the post, it was voted for. So is this possible and if not, how can I achieve this?
Thanks!
You could use ClientIdMode and set it to predictable
http://msdn.microsoft.com/en-us/library/system.web.ui.clientidmode.aspx
<asp:ListView ID="ListView1"
ClientIDMode="Predictable"
ClientIDRowSuffix="ProductID"
DataSourceID="XmlDataSource1" runat="server" >
<ItemTemplate>
</ItemTemplate>
</asp:ListView>
This assumes you are using .Net 4.0 or above.

Inline Code in markup page in ASP.NET Webforms?

Is something similiar to the following pseduocode possible on server side controls?
<asp:Label runat="server" ID="lbl" Text=<%=DateTime.Now.ToString(); %> />
I.e. assigning attributes.
This will work for databound controls, e.g.
<asp:Label runat="server" ID="lbl" Text="<%# DateTime.Now.ToString() %>" />
Then in your code behind, you'll need to call lbl.DataBind().
Try this:
<asp:Label runat="server" ID="lbl" Text='<%=DateTime.Now.ToString()%>' />

Categories