Posts tagged ‘Asp.net’

Hyperlinked Images in ASP.NET GridView (Open content in new page)

Solution : 1

TemplateField with Hyperlink and img Element

<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink runat=”server” NavigateUrl='<%# Eval(“PAGE_Or_PDF_URL”) %>’
Target=”_blank”>
<img src='<%# Eval(“Image_URL”) %>’ alt=”PDF IMAGE” />
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>

Solution : 2
TemplateField with ImageButton

<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton runat=”server” ImageUrl='<%# Eval(“Image_URL”) %>’
PostBackUrl='<%# Eval(“Target_URL”) %>’ AlternateText=”Alternate Text” />
</ItemTemplate>
</asp:TemplateField>
Solution : 3

TemplateField with Javascript
<asp:TemplateField>

<asp:ImageButton ID=”ImageButton1″ runat=”server” ImageUrl='<%# Eval(“Image_URL”) %>’ OnClientClick='<%# String.Format (“javascript:return openTargetURL(\”{0}\”)”, Eval(“Target_URL”)) %>’ AlternateText=”Alternate Text” />

</asp:TemplateField>

Advertisements

Check Transaction amount having decimal point or not

Using Below code, we can trace entered amount has decimal point or not.

AMOUNT = 500.25;

AMOUNT.ToString().IndexOf(“.”) != -1

AMOUNT.ToString().IndexOf(“.”) returns -1 if amount has no decimal point

AMOUNT.ToString().IndexOf(“.”) returns >0 value if amout has decimal point.

 

Open PDF File in Web Browser using C# Asp.net

Using below code, no need to open file physically. We can also protect file to open from authorize access.

OpenPDF.aspx

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”OpenPDF.aspx.cs” Inherits=”OpenPDF” %>

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head runat=”server”>
<title></title>
</head>
<body>
<form id=”form1″ runat=”server”>
<h3 style=”color: #0000FF”>Open PDF files using ASP.NET</h3>
<div>
<asp:Button ID=”btnpdf” runat=”server” Text=”Click for open PDF file” Font-Bold=”True” OnClick=”btnpdf_Click” />
</div>
</form>
</body>
</html>

OpenPDF.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;

public partial class OpenPDF : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnpdf_Click(object sender, EventArgs e)
{
string FilePath = Server.MapPath(“test.pdf”);
WebClient User = new WebClient();
Byte[] FileBuffer = User.DownloadData(FilePath);
if (FileBuffer != null)
{
Response.ContentType = “application/pdf”;
Response.AddHeader(“content-length”, FileBuffer.Length.ToString());
Response.BinaryWrite(FileBuffer);
}
}
}

If this blog is helpful to you, Pls. click on like it.

How to use c# and vb code file in same Asp.net project.

You may use both language in same application. Just create different folder like vb and csharp inside app_code then made changes inside web.cofing you may use. This way we tell compiler to compile code in vb or c# language.

Write below code in your web.config file under compilation element.

<compilation debug=”true” strict=”true” explicit=”true”>
<codeSubDirectories>
<add directoryName=”VBCode” />
<add directoryName=”CSCode” />
</codeSubDirectories>

</compilation>