Wednesday 10 April 2013

ASP.net : Image zoom using Jquery and Elevate plug-in | Neha Sharma



Introduction:

This article is about to explain how to create Image zoom in ASP.Net using Jquery and Elevate plug-in.

Requirement:

1.       Download Elevate plug-in

Code :

Write the below code in to your page :

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Image zoom</title>
    <script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
       <script src='jquery.elevateZoom-2.5.3.min.js'></script></head>
    <%--<script src='jquery.fancybox.js'></script>--%>
 
<body>
<div>
    <asp:Image ID="Image1" runat="server" ImageUrl="small/image_1.jpg" data-zoom-image="large/image_1.jpg"/>
 </div>
<script>
    $("# Image1").elevateZoom({ gallery: 'gallery_01', cursor: 'pointer', galleryActiveClass: 'active' });

    //pass the images to Fancybox
    $("# Image1").bind("click", function (e) {
        var ez = $('# Image1).data('elevateZoom');
        return false;
    });
</script>
</body>
</html>

Save all and run view the page in browser it ll work perfectly.

Thanks

Neha Sharma

Monday 8 April 2013

ASP.Net:Create RSS Feed | Neha Sharma


Introduction:

This article is about to create RSS feed in asp.net

Procedure:

To create a rss feed follow below steps here:

1.       Add below line in to rss page under the page directive line like below :
<%@ OutputCache Duration="120" VaryByParam="*" %>

2.       Create a table with the field Id,title,description and url and enter some dummy data like :


        3.   Add the below code on page load :


string connectionString = "Data Source=name;Initial Catalog=db name;Integrated Security=True";
DataTable d_t = new DataTable();
SqlConnection conn = new SqlConnection(connectionString);
using (conn)
{
SqlDataAdapter adp = new SqlDataAdapter("SELECT * from tablename", conn);
adp.Fill(d_t);
}

Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter Text_Writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
Text_Writer.WriteStartDocument();
//Below tags are mandatory rss
Text_Writer.WriteStartElement("rss");
Text_Writer.WriteAttributeString("version", "2.0");
// Channel tag will contain RSS feed details
Text_Writer.WriteStartElement("channel");
Text_Writer.WriteElementString("title", " ASP.NET ");
Text_Writer.WriteElementString("link", "http://nehaprogrammer.blogspot.com");
Text_Writer.WriteElementString("description", " C#.NET,ASP.NET ");
Text_Writer.WriteElementString("copyright", "Copyright 2013 - 2014 nehaprogrammer.blogspot.com. All rights reserved.");
foreach (DataRow oFeedItem in d_t.Rows)
{
Text_Writer.WriteStartElement("item");
Text_Writer.WriteElementString("title", oFeedItem["Title"].ToString());
Text_Writer.WriteElementString("description", oFeedItem["Description"].ToString());
Text_Writer.WriteElementString("link", oFeedItem["URL"].ToString());
Text_Writer.WriteEndElement();
}
Text_Writer.WriteEndElement();
Text_Writer.WriteEndElement();
Text_Writer.WriteEndDocument();
Text_Writer.Flush();
Text_Writer.Close();
Response.End();

}

Save all and view the page in browser. It  ll work perfectly.

Thanks


ASP.Net: Convert aspx page in to Pdf | Neha Sharma



Introduction:

This article is about to export an aspx page in to Pdf file.

Requirement:

The only requirement is to add dll of “ITextSharp” in to the application.

Code:

In code behind add below namespaces:
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Drawing;

Design a page.

Place below code on the button click event to convert aspx page in to pdf .

protected void Button1_Click(object sender, EventArgs e)
    {
        string attachment = "attachment; filename=" + "abc" + ".pdf";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/pdf";
        StringWriter s_tw = new StringWriter();
        HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
        h_textw.AddStyleAttribute("font-size", "7pt");
        h_textw.AddStyleAttribute("color", "Black");
        Panel1.RenderControl(h_textw);//Name of the Panel
        Document doc = new Document();
        doc = new Document(PageSize.A4, 5, 5, 15, 5);
        FontFactory.GetFont("Verdana", 80, iTextSharp.text.Color.RED);
        PdfWriter.GetInstance(doc, Response.OutputStream);
        doc.Open();

        StringReader s_tr = new StringReader(s_tw.ToString());
        HTMLWorker html_worker = new HTMLWorker(doc);
        html_worker.Parse(s_tr);

        doc.Close();
        Response.Write(doc);
    }
public override void VerifyRenderingInServerForm(Control control)
    {


    }

Save all and run an error ll occur like the below image



This error occurs when we render a control in to response. Follow the below point to come out from this error:

Add  EnableEventValidation="false" in the page directive on the source of your page at the top

Now save all and view page in browser when you click on the button to convert apx page in to Pdf it ll 
work.


Thanks

Friday 5 April 2013

ASP.Net : Resize Fonts | Neha Sharma


Live Demo

Hello everyone!

Today i learned a small but interesting and important task this is how to re-size the font .

Write the below code in to your deault.aspx page.

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


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Resize Fonts</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript">
    $(document).ready(function () {
        var divtxt = $('#f_div');
        // Increase Font Size
        $('#btnincfont').click(function () {
            var curSize = divtxt.css('fontSize');
            var newSize = parseInt(curSize.replace("px", "")) + 1;
            $(divtxt).css("fontSize", newSize + "px");
        });
        // Decrease Font Size
        $('#btndecfont').click(function () {
            var curSize = divtxt.css('fontSize');
            var newSize = parseInt(curSize.replace("px", "")) - 1;
            $(divtxt).css("fontSize", newSize + "px");
        })
    });
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="f_div">
hello this is a test page having test text
    <br />
    just to show you the code demo
to make fonts large and small.
    <br />
    <br />
    Click on &quot;+&quot; symbol to make fonts large or
    <br />
    CLick on &quot;-&quot; symbol to make fonts small.</div><br />
<input type="button" id="btnincfont" value=" + " />
<input type="button" id="btndecfont" value=" - " />
</form>
</body>
</html>

Save all and run this page in browser.


Thanks.

Which Game Engine you should choose | Neha Sharma

Unity3D and Unreal Engine are only 2 Game engine which executes an indispensable position in Game Industry. The choice of the engine must ...