LIKE US ON FACE BOOK

Wednesday, 24 April 2013

Adding Custom Error Page to Asp.net Project

Hi Friends,

Please do follow these steps for Adding Custom Error Page.

>
     Create a error Page for eg:- error.aspx

>
     add entry to app setting ,if you have
     like this  
          
    <add key="Errorpage" value="/errorpage.aspx"/>

>  add entry to appsecurity,if you have 
    ike this 

   <page name ="error page" url="/projectname/errorpage.aspx">

      define any access rule or httpget or httpost 

  </page> 

>
   Main thing is make entry in web.config as below
  
  <configuaration> 
         <system.web>  
                       <customerrors mode="On" defaultRedirect="/error.aspx"/>
        </system.web>
  </configuaration>
   
Any doubts please do ask.

Tuesday, 16 April 2013

Comparing With RegEx and Adding Contents of Textbox to ASP ListBox Using JQuery




function Compare&Add() {      

            var regex = /^Your Regular Expression$/;          
            var str = $("[id$='textboxid']").val();
               var options = $("[id$='listboxid'] option");
            var alreadyexist = false;
           $("[id$='_promtlabel']").hide();
          if (str.match(regex)) {
              $(options).each(function () {
                  if ($(this).val() == str) {
                       $("[id$='_promtlabel']").show();
                      alreadyexist = true;
                      return;
                   }
              })
               if (!alreadyexist) {
                  $("[id$='listboxid']").append($("<option value = " + str + ">" + str + "</option>"));
                   $("[id$='textboxid']").val('');
                   return false;
              }          

        }

Here is Simple Code by using JQuery,Pushing up the Textbox value to Listbox in Asp.Net

If Any Doubts Please Comment...

Wednesday, 10 April 2013

Writing C# Code in JavaScript & Using Window.Location.href to reload Page in Javascript

Guys Here is Simplest Code ,I wrote it for my Work.


file.aspx:-

<input type="button" class="button" id="btncancle" onclick="javascript:cancle()"/>

Here is Java Script Used:--

function cancle(){
     window.location.href="Notification.aspx?ID=<%=base.WebsiteID%>";
}

Here <%=base.WebsiteID%>" is C# code called into javascript


Any Doubts Please do ask,Thanks Guys

Thursday, 21 March 2013

Writing Conditional HTML tag for adding attributes in Asp.Net or Php or Java using ternary Operator.

Here is what I did..
while some task was assigned to me..

<input type=\"" + (this.applymobilelookandfeel ? "number" : "text") + "\" >


The this.applymobilelookandfeel is conditional statement using ternary(? :) operator.

Number will be if condition is true,else text if condition fails.


Any doubts Please do comment.will be glad to reply back.....

Friday, 22 February 2013

Uploading Single/Multiple Files in ASP.Net without using any Plug-in or Jquery

Here is most simplest way i found while working on .....
U guys no need to google further..I bet it..

create a file called Filename.aspx.cs 

write a this code 


<div>
        <input type="file" id="FileUpload1" multiple="multiple" runat="server"/>

        <asp:Button runat="server" ID="btnupload" Text="Upload"
            onclick="btnupload_Click"/>&nbsp;<br/>

        <asp:Label runat="server" ID="Label1"></asp:Label> 
</div>

Filename.aspx.cs

protected void btnupload_Click(object sender, EventArgs e)
    {
      string tempPath =          System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
       string savepath = Server.MapPath(tempPath);
        for(int i=0;i<Request.Files.Count;i++)
        {            
            HttpPostedFile hpf = Request.Files[i];
            string filename = hpf.FileName;
            hpf.SaveAs(savepath + @"\" + filename);
        }

    } 
Web.config

<appSettings>
    <add key ="FolderPath" value ="uploads"/>
</appSettings > 

Any Doubts regarding this please do ask...

Monday, 4 February 2013

READING AND ACCESSING DATA FROM XML IN ASP.NET

HERE TODAY AM GONNA GIVE U VERY SIMPLE CODE...
I DONT BELIV IT HAS TO BE EXPLAINED BECOZ..ITS VERY MUCH UNDERSTANDABLE..
STILL ILL COMMENT OUT POINTS..WAT'S HAPPENIN IN CODE...


CREATE A FILE WITH NAME AS follows:-

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title></title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
   
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       Employee Information<br />
       Name:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
       <br />
       Emp-Id:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
       <br />
       Qualification:<asp:DropDownList ID="DropDownList1" runat="server"
           AutoPostBack="True">
           <asp:ListItem>--SELECT--</asp:ListItem>
           <asp:ListItem>MTEC</asp:ListItem>
           <asp:ListItem>BE</asp:ListItem>
           <asp:ListItem>BTEC</asp:ListItem>
           <asp:ListItem>MBBS</asp:ListItem>
           <asp:ListItem>BDS</asp:ListItem>
       </asp:DropDownList>
   
       <br />
       <asp:Button ID="Button1" runat="server" Text="SUBMIT" onclick="Button1_Click" />
       <asp:Button ID="Button2" runat="server" Text="SHOW" onclick="Button2_Click" />
       <br />
       <br />
       <asp:DataList ID="DataList1" runat="server" CellPadding="4" ForeColor="#333333">
           <AlternatingItemStyle BackColor="White" ForeColor="#284775" />
           <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
           <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
           <ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />
           <ItemTemplate>
               <hr />
               Name:<%#DataBinder.Eval(Container.DataItem,"name")%><br />Emp-ID:<%#DataBinder.Eval(Container.DataItem,"Emp-Id")%>></a><br />
               Qualification:<%#DataBinder.Eval(Container.DataItem,"Qualification")%>><br />
           </ItemTemplate>
           <SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
       </asp:DataList>
   
   </div>
   </form>
</body>
</html>

Employee.xml
<?xml version="1.0" encoding="utf-8"?>
<Employeeinformation>

</Employeeinformation>

Xmlreadrite.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.Data;
using System.Xml;

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

here we retrive data from xml file to datalist by using dataset.

   private void BindDatalist()
   {
       XmlTextReader xmlreader=new XmlTextReader(Server.MapPath("Employee.xml"));
       DataSet da = new DataSet();
       da.ReadXml(xmlreader);
       xmlreader.Close();
       if (da.Tables.Count != 0)
       {
           DataList1.DataSource = da;
           DataList1.DataBind();
       }
       else
       {
           DataList1.DataSource = null;
           DataList1.DataBind();
       }
   }


here we insert the data to xml file by creating xml object and assignin it to our xml file.

   protected void Button1_Click(object sender, EventArgs e)
   {
       XmlDocument xmldoc = new XmlDocument();
       xmldoc.Load(Server.MapPath("Employee.xml"));
       XmlElement parentelement = xmldoc.CreateElement("Details");
       XmlElement name = xmldoc.CreateElement("name");
       name.InnerText = TextBox1.Text;
       XmlElement EmpId = xmldoc.CreateElement("Emp-Id");
       EmpId.InnerText = TextBox2.Text;
       XmlElement Qualification = xmldoc.CreateElement("Qualification");
       Qualification.InnerText = DropDownList1.SelectedItem.Text;
       parentelement.AppendChild(name);
       parentelement.AppendChild(EmpId);
       parentelement.AppendChild(Qualification);
       xmldoc.DocumentElement.AppendChild(parentelement);
       xmldoc.Save(Server.MapPath("Employee.xml"));
   }

here in this button click we call display function ,whic is binddatalist()

   protected void Button2_Click(object sender, EventArgs e)
   {
      
       BindDatalist();

   }
}