HTML MAILTO hyperlink doesn't respond - vb.net

My hyperlink doesn't open up an email with my database text value.
I have a previous application that uses this exact format and works; however, for this application it doesn't.
One of the many examples I have referenced is: ASP.NET mailto: misfunction
my Database column name is email_Own and so I have tried to DataItem.email_Own and DataItem.email like other examples show to see if whether the value after DataItem is the database column name or not. Both don't work.
Working EX
My other application showed an email within a gridview so I am wondering if that is the reason why the coding below worked:
<asp:TemplateField HeaderText="Description" >
<ItemTemplate >
<br /><br />
Email:
<asp:HyperLink id="lnkEmail" cssClass="emailColor" runat="server" text='<%#DataBinder.Eval(Container, "DataItem.email") %>' NavigateUrl='<%#DataBinder.Eval(Container, "DataItem.email","MAILTO:{0}")%>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Coding that doesn't work:
Any suggestions for the coding below? This hyperlink is inside a table.
<tr>
<td width="25%">
<font class="Blackfont" size="2" > <b>Owner Email </b> </font>
</td>
<td>
<asp:HyperLink id="Owner_E" runat="server" text='<%#DataBinder.Eval(Container, "DataItem.email") %>' NavigateUrl='<%#DataBinder.Eval(Container, "DataItem.email","MAILTO:{0}")%>'Font-Size="10pt"></asp:HyperLink>
</td>
</tr>
The text of the hyperlink shows up correctly when the page loads. Its the linking to mail that isn't working.
I also tried this code snippet instead but the hyperlink doesn't respond as well: NavigateUrl='<%#Bind("email_Own", "mailto:{0}") %>' Text='<%#Bind("email_Own") %>'
FYI:
I am not sure if this changes anything but I fill the hyperlink in VB.net like so:
If Not DsAds.Tables(0).Rows(0).Item(14) Is DBNull.Value Then
lnkEmail.Text = DsAds.Tables(0).Rows(0).Item(14)
End If
where DsAds is a dataset
The HTML source code shows this:

I referenced http://forums.asp.net/t/1071308.aspx?mailto+link+in+textbox
Like so:
<asp:HyperLink id="lnkEmail" runat="server" Font-Size="10pt" ></asp:HyperLink>
and in Page Load[at end of it] I add:
lnkEmail.NavigateUrl = "mailto:" + DsAds.Tables(0).Rows(0).Item(14)
lnkEmail.Text = DsAds.Tables(0).Rows(0).Item(14)

Related

how to pass variable in the url from gridview in vb.net

I have Gridview of the form results. I am trying to add an url to one of the field. How do I pass the variable in the url. intLib is the variable. This is what I have:
VB.Net Code:
<a href="EditIncident.aspx?ID=<%# Eval("Inci_ID")%>&Val2="& intLib>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Inci_ID") %>'></asp:Label>
</a>
I created a session variable and passed it on to the next page.
Thanks for your help.

How to set DataNavigateUrlFormatString dynamically ? or How to eval Page.User.Identity.Name on a webpage?

I am building a GridView which can download songs. So I use a hyperlink fileld and use DateNavigateUrlFormatString.
E.G.
DataNavigateUrlFormatString="~/uploads/{0}"
Now,
I need to combine Page.User.Identity.Name into DateNavigateUrlFormatString
For example,
DataNavigateUrlFormatString="~/uploads/UserName/{0}" which Page.User.Identity.Name depending on the user login.
I tried to access DataNavigateUrlFormatString from the code behind but I couldn't.
I tried to use Eval such as
'~/uploads/" <%# Eval("Page.User.Identity.Name") %> /{0}'
this doesn't work as well.
Hope someone could point me out.
Thanks,
L
FInal Solution
<asp:TemplateField HeaderText="Play">
<ItemTemplate>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl = '<%# String.Format("~/UserUploads/{0}/",Page.User.Identity.Name)+ "/" + Eval("Song_Name") %>' Text="Play" >
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
DataNavigateUrlFormatString expects the placeholder(s) to come from fields in the datasource of the control.
My suggestion is that since you already know the url you are trying to build you could set the NavigateUrl property of hyperlink control.
NavigateUrl = '<%# String.Format("~/UserUploads/{0}/",Page.User.Identity.Name)+ "/" + Eval("Song_Name") %>'

Sort the Pictures in Datalist Control

I Have a Datalist Control and Reading the pictures from folder and showing them in lightbox from Datalist i am also reading data and time from those pictures.Ist thing is that the datalist is not reading the Date picture taken from the attributes and second is that pictures are not being sorted in desc order of date picture taken.Please anyone tell me how can i complete these taskes.
My data list code is here
<asp:DataList ID="DataList1" runat="server" RepeatColumns="5" RepeatDirection="Horizontal" Width="23%" CellPadding="2" CellSpacing="0" Height="270px" HorizontalAlign="Center">
<ItemTemplate>
<asp:Image Width="200px" height="200px" ID="Image1" ImageUrl='<%# Bind("Name", "~/MMS/1 Box/{0}") %>' runat="server" />
<br />
<asp:HyperLink ID="HyperLink1" rel="lightbox[roadtrip]" title='<%# DataBinder.Eval(Container.DataItem, "LastWriteTime", "{0:yyyy-MM-dd hh:mm:ss}") %>'
Text="Zoom" NavigateUrl='<%# Bind("Name", "~/MMS/1 Box/{0}") %>' runat="server"/>
</ItemTemplate>
<ItemStyle BorderColor="Silver" BorderStyle="Dotted" BorderWidth="1px" HorizontalAlign="Center"
VerticalAlign="Bottom" />
</asp:DataList>
and to read the Images from folder my vb.net code is here
Sub loadimage()
Dim sdir As New DirectoryInfo(MapPath("~/MMS/1 Box"))
Dim file As FileInfo() = sdir.GetFiles()
Dim list As New ArrayList()
For Each file2 As FileInfo In file
If file2.Extension = ".jpg" OrElse file2.Extension = ".gif" OrElse file2.Extension = ".bmp" Then
list.Add(file2)
End If
Next
DataList1.DataSource = list
DataList1.DataBind()
End Sub
Anyone tell me what change should i have to make in code so that my both requirements will be completed as well
Use IComparable to sort your list based on time creation time or whatever attribute you want to sort it.
Here is a link which would help you implement this: http://www.knowdotnet.com/articles/sortarraylistofobjects.html

VB.net: Accessing data from DataList in Page_Load

New to VB.net, and trying to re-factor an 'old-skool' ASP page where all the page logic is happening on the .aspx page itself, to code-behind. Basically, I have a button that has a state, either on or off. If on, I set a hidden field to 1, if off, I set it to 0 (the default when a user visits the page).
The goal is to simply change the message I am sending to the user.
Have the following relevant code in MyPage.aspx:
<asp:HiddenField ID="hfldState" runat="server" Visible="false" Value="0" />
<div id="mainContent">
<asp:Literal ID="lblMessage" runat="server"
Visible="false" />
<asp:DataList ID="dlList" runat="server"
DataSourceID="sdsList"
DataKeyField="Entry No_"
RepeatLayout="Flow">
<ItemTemplate>
<div>
<asp:HyperLink ID="hlCurriculum" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>'
NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "File Path") %>'
ToolTip='<%# DataBinder.Eval(Container.DataItem, "Title") %>'
Target="_blank"
Style="font-weight: bold;">
</asp:HyperLink>
</div>
</ItemTemplate>
</asp:DataList>
</div>
<asp:SqlDataSource ID="sdsList" runat="server"
ConnectionString="..."
SelectCommand="SELECT [Entry No_], [Title], [File Path] FROM [Table] WHERE ([State] = #State)">
<SelectParameters>
<asp:ControlParameter ControlID="hfldState" Name="State" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
And the following in the Page_Load Sub:
If Page.IsPostBack Then
' Check for results
dlList.DataBind()
If dlList.Items.Count > 0 Then
' Results, display them
lblMessage.Text = "<h3>Results</h3>"
lblMessage.Visible = True
Else
' No results
lblMessage.Text = "<p>No Results</p>"
lblMessage.Visible = True
End If
Else
' user has not clicked anything
lblMessage.Text = "<p>Click button!</p>"
End If
The above code produces the following effect: when I click the button, setting the state to 1 and the page reloads, in Page_Load, I am getting zero results from the If dlList.Items.Count > 0 Then check, and thus am showing the 'No results' message, but the actual asp:DataList on the MyPage.aspx page is returning results... and then if I click the button again, setting it back to 0, in Page_Load, the datalist is now returning results, so I set the text to 'Results', but again, the control on the MyPage.aspx page behaves correctly, and shows no results, as expected. Now keep in mind that the above works perfectly in terms of checking the number of results if I move the If dlList.Items.Count > 0 Then page logic out of Page_Load and back to the MyPage.aspx file, it all works fine (i.e. results when state = 1, none when state = 0)
Any ideas?
I dont see a check in your page load for a postback:
If Not IsPostBack
'code
dList.DataBind() 'here is where you want to bind the data...
end if
The issue related to my ignorance of the page lifecycle in VB.net. Solution was to adjust the visibility of the asp:Literal, asp:DataList, set values etc in Page_PreRenderComplete. Basically, the asp:DataList wasn't being set in Page_Load, as expected, so doing any kind of logic in Page_Load based on the item count didn't make any sense.

Making asp:Label a specific HTML tag

New to VB.net, just trying to figure out how to properly manipulate the asp:Label control.
I have a page that, based on if there are results, etc should display an <h1></h1> tag with a header, then the data. As I am using the code-behind model, my user facing page essentially just has the following:
<asp:Label ID="lblMessage" runat="server"
Visible="false" />
<asp:DataList ID="dlCurriculumLists" runat="server"
DataSourceID="sdsCurriculumLists"
DataKeyField="Entry No_"
RepeatLayout="Flow"
Visible="false">
<ItemTemplate>
<div>
<asp:HyperLink ID="hlCurriculum" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>'
NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "File Path") %>'
ToolTip='<%# DataBinder.Eval(Container.DataItem, "Title") %>'
Target="_blank"
Style="font-weight: bold;">
</asp:HyperLink>
</div>
</ItemTemplate>
</asp:DataList>
On my code-behind page, I then set the asp:Label and asp:DataList to Visible="true" based on the data from the database. Here's the catch - if there is data, I want to set lblMessage to be an H1, and if not, just standard Label text. I realize I can emulate the look through the CSS, but was just hoping there was another way (maybe similar to the ItemTemplate concept) to specify the HTML type of the Label control - it appears to be a by default.
For people coming from a VB background, it's a common mistake to think that the most basic control for displaying arbitary text is a Label.
That's not true. A label should label something, usually another UI control (that's what the AssociatedControlId property is for).
If you just want to display arbitrary text or HTML markup, use something more basic instead. Some examples are asp:Literal, asp:Placeholder or asp:Localize.
Using, for example, an asp:Literal called myLiteral, you can easily create a heading in code:
myLiteral.Text = "<h1>" & Server.HtmlEncode(myHeading) & "</h1>"
As far as I know, the asp:Label component will always generate a <label> HTML tag when its AssociatedControlId attribute is set.
What you could do instead is use a Literal Control and populate it with the HTML you wish at runtime.
UPDATE
One thing you could do to make this work as required using your current Label control is to have a theme for the label that marks it up as a H1. You could then toggle the controls EnableTheming property as required.
Aside from what already has been suggested here, you can also implement your own ASP.NET control with any properties you want, then modify its rendering on the fly, depending on the properties' values. It is pretty fun to do and is not as hard as one might think. Here is some information on the subject: http://msdn.microsoft.com/en-us/library/vstudio/zt27tfhy(v=vs.100).aspx