Sunday, 1 November 2015

check valid date time or not

  public bool IsValidDatetime(string strValue)
        {

            //return Convert.ToDateTime(strValue)
            DateTime fromDateValue;
            string s = "15/07/2012";
            var formats = new[] { "dd/MM/yyyy", "yyyy-MM-dd" };
            if (DateTime.TryParseExact(s, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out fromDateValue))
            {
                return true;
                // do for valid date
            }
            else
            {
                return false;
                // do for invalid date
            }
        }

Wednesday, 28 October 2015

How to disable back button after login in c#(Web application)

Add it in deafult.aspx page

<script type="text/javascript">
        window.history.forward();
        function noBack() { window.history.forward(); }

    </script>

Tuesday, 22 September 2015

HTTP Error 500.21 - Internal Server Error Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list

HTTP Error 500.21 - Internal Server Error

Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list




First need to installed aspnet_regiis

the aspnet_regiis is in the bellow path 
C:\Windows\Microsoft.NET\Framework\v4.0.30319


Go to command prompt right click on cmd prompt Run as administrator  and go to the path then type aspnet_regiis.exe -i that's it

Thursday, 11 September 2014

Could not load file or assembly 'EntityFramework' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

Could not load file or assembly 'EntityFramework' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))



To solve the above error you have to do the following things:

Solution:
Clear out the temporary framework files for your project in:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ 


For Windows 7, the path is:
C:\Users\[username]\AppData\Local\Temp\Temporary ASP.NET Files\

For 64 bit systems with 'Framework' in the path the full path is:
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\



Thursday, 15 May 2014

Windows service through CMD

To create a service with out using visual studio:
 
We need the exe file what we have to create the ser vice
 sc create **Abcd** start= auto binPath= "E:\Projects\Service\bin\Debug\Service.exe"
 
To Delete a windows Service through CMD:
sc delete **Abcd**

How to send a mail using SMTP server in Dotnet

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Web;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using HELP;
using System.Web.Configuration;


public bool SendingMail(string strBody = "", string strToMail = "", string subject = "Forgot Password Details.")
        {
            try
            {
                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                SmtpClient smtp = new SmtpClient();
                smtp.Host = WebConfigurationManager.AppSettings["SMTP_Host"].ToString();
                smtp.EnableSsl = true;
                NetworkCredential NetworkCred = new NetworkCredential();
                NetworkCred.UserName = WebConfigurationManager.AppSettings["SMTP_UserName"].ToString();
                NetworkCred.Password = WebConfigurationManager.AppSettings["SMTP_Password"].ToString();
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = NetworkCred;
                smtp.Port = Convert.ToInt32(WebConfigurationManager.AppSettings["SMTP_Port"].ToString());
                msg.To.Add(strToMail);
                msg.From = new MailAddress(WebConfigurationManager.AppSettings["FromEmail"].ToString());
                msg.Subject = subject;
                ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
                msg.Body = strBody;
                msg.IsBodyHtml = true;
                smtp.Send(msg);

                return true;
            }
            catch (SmtpException ex)
            {
                return false;
            }
        }



Call from Front end this method in button click.

Tuesday, 22 April 2014

Create a Pop Up Using JavaScript and CSS when click event

<div id="toPopup" style="background: none repeat scroll 0 0 #FFFFFF; border: 10px solid #ccc; border-radius: 3px 3px 3px 3px; color: #333333; display: none; font-size: 14px; left: 50%; margin-left: -402px; position: fixed; top: 20%; width: 800px; z-index: 2;">
    <div class="close" style="background: url('../images/close.png'); cursor: pointer; height: 30px; position: absolute; right: -27px; top: -24px; width: 30px;"></div>
    <span class="ecs_tooltip" style="background: none repeat scroll 0 0 #000000; border-radius: 2px 2px 2px 2px; color: #FFFFFF; display: none; font-size: 11px; height: 16px; opacity: 0.7; padding: 4px 3px 2px 5px; position: absolute; right: -62px; text-align: center; top: -51px; width: 93px;">Press Esc to close
        <span class="arrow" style="border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 7px solid #000000; display: block; height: 1px; left: 40px; position: relative; top: 3px; width: 1px;"></span></span>
    <div id="popup_content" style="margin: 4px 7px;">

"Pop up content"
 </div>

</div>
<div class="loader" style="background: url('../images/Spinningloading.gif'); height: 32px; width: 32px; display: none; z-index: 9999; top: 40%; left: 50%; position: absolute; margin-left: -10px;"></div>
<div id="backgroundPopup" style="z-index: 1; position: fixed; display: none; height: 100%; width: 100%; background: #000000; top: 0px; left: 0px;"></div>

<script type="text/javascript">
    $(document).ready(function () {
        function Click() {
            loading(); // loading
            setTimeout(function () { // then show popup, deley in .5 second
                loadPopup(); // function show popup
            }, 500); // .5 second
            return false;

        }
        $("div.close").hover(
              function () {
                  $('span.ecs_tooltip').show();
              },
                            function () {
                                $('span.ecs_tooltip').hide();
                            }
               );

        $("div.close").click(function () {
            disablePopup();  // function close pop up
        });

        $(this).keyup(function (event) {
            if (event.which == 27) { // 27 is 'Ecs' in the keyboard
                disablePopup();  // function close pop up
            }
        });

        $("div#backgroundPopup").click(function () {
            disablePopup();  // function close pop up
        });
       
        function loading() {
            $("div.loader").show();
        }
        function closeloading() {
            $("div.loader").fadeOut('normal');
        }

        var popupStatus = 0;

        function loadPopup() {
            if (popupStatus == 0) { // if value is 0, show popup
                closeloading(); // fadeout loading
                $("#toPopup").fadeIn(0500); // fadein popup div
                $("#backgroundPopup").css("opacity", "0.7"); // css opacity, supports IE7, IE8
                $("#backgroundPopup").fadeIn(0001);
                popupStatus = 1; // and set value to 1
            }
        }

        function disablePopup() {
            if (popupStatus == 1) { // if value is 1, close popup
                $("#toPopup").fadeOut("normal");
                $("#backgroundPopup").fadeOut("normal");
                popupStatus = 0;  // and set value to 0
            }
        }

    
    });
</script>

Friday, 11 April 2014

How to enter data in only 1 textbox if we have 2 textbox's in our page using jquery (generics)(2nd box will set to readdonly)

 <script type="text/javascript">      
        function OnChangeEventforpercentage() {
            compareValues(document.getElementById('x'), document.getElementById('y'));
        }

        function OnChangeEventfordiscount() {
            compareValues(document.getElementById('y'), document.getElementById('x'));
        }


        function compareValues(x, y) {          
            var value = x.value;         
           if (value == "") {
                $(y).prop('readonly', false);
            }
            else if (value != "" ) {
                $(y).prop('readonly', true);
            }
          
           
        }

    </script>

Wednesday, 2 April 2014

HTTP Error 500.21 - Internal Server Error Handler "ExtensionlessUrlHandler-Integrated-4.0" has a bad module "ManagedPipelineHandler" in its module list in IIS7.0 (MVC4.0)

To overcome this error go to command prompt right click on it and select run as administrator and type the following

%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

                                  or

%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i

You can get the bellow cmd. PFA

Note: Don't change the directory of CMD.


How to check From date , To date using jquery in generic format


    function IsDateNull(dateValue) {
        if (dateValue == null || dateValue == "") {
            return false;
        }
        else {
            return true;
        }
    }

    function IsValidDate(validDate) {
        var validformat = /^\d{1,2}\/\d{1,2}\/\d{4}$/; //Basic check for format validity
        var a = validDate.match(validformat);
        if (a == null)
            return false;
        var item = [];
        item = a[0].split('/');
        if (item[0] < 1 || item[0] > 12)
            return false;
        else if (item[1] < 1 || item[1] > 31)
            return false;
        else if ((item[0] == 4 || item[0] == 6 || item[0] == 9 || item[0] == 11) && item[1] == 31)
            return false;
        else if (item[0] == 2) {
            var isleap = (item[2] % 4 == 0 && (item[2] % 100 != 0 || item[2] % 400 == 0));
            if (item[1] > 29 || (item[1] == 29 && !isleap))
                return false;
        }

    }

    function IsValidDateRange(validDateRange) {//Detailed check for valid date ranges
        var monthfield = validDateRange.split("/")[0]
        var dayfield = validDateRange.split("/")[1]
        var yearfield = validDateRange.split("/")[2]
        var dayobj = new Date(yearfield, monthfield - 1, dayfield)
        if ((dayobj.getMonth() + 1 != monthfield) || (dayobj.getDate() != dayfield) || (yearfield < 1753 || yearfield > 9999)) {
            return false;
        }
        else {
            return true;
        }
    }

    function DateAlert(DateType) {
        return "Please Enter or Select a Valid " + DateType + " Date(Ex:MM/DD/YYYY).";
    }

    function ValidDateAlert(DateType) {
        return "Please Enter or Select a Valid " + DateType + " Date(Ex:MM/DD/YYYY). And year should be greater than equal to 1753 and less than equal to 9999.";
    }

    function InValidDateAlert(DateType) {
        return "Invalid " + DateType + " Date";
    }

    function CheckDates(FromID, ToID) {
        var IsfromDate = true;
        var FromDate = $(FromID).val();
        var IsToDate = true;
        var ToDate = $(ToID).val();
        var fromDateObj = new Date(FromDate);
        var toDateObj = new Date(ToDate);
        if (IsDateNull(FromDate) == false) {
            IsfromDate = false;
            alert(DateAlert("From"));
            $(FromID).focus();
            return false;
        }
        else {
            if (IsValidDate(FromDate) == false) {
                IsfromDate = false;
                alert(InValidDateAlert("From"));
                $(FromID).focus();
                return false;
            }
            else {
                if (IsValidDateRange(FromDate) == false) {
                    IsfromDate = false;
                    alert(ValidDateAlert("From"));
                    $(FromID).focus();
                    return false;
                }
            }
        }
        if (IsfromDate == true) {
            if (IsDateNull(ToDate) == false) {
                IsToDate = false;
                alert(DateAlert("To"));
                $(ToID).focus();
                return false;
            }
            else {
                if (IsValidDate(ToDate) == false) {
                    IsToDate = false;
                    alert(InValidDateAlert("To"));
                    $(ToID).focus();
                    return false;
                }
                else {
                    if (IsValidDateRange(ToDate) == false) {
                        IsToDate = false;
                        alert(ValidDateAlert("To"));
                        $(ToID).focus();
                        return false;
                    }
                }
            }
            if (IsfromDate == true && IsToDate == true) {
                if (fromDateObj > toDateObj) {
                    alert("Please ensure that the From Date is greater than or equal to the To Date.");
                    $(FromID).focus();
                    return false;
                }
                else {
                    return true;
                }
            }
        }
    }

Thursday, 27 March 2014

How to find table tr td using Jquery

  $('table tr').each(function () {
                //if ($(this).find('.ruletype').eq(0).text() == $("#RuleType").val()) {
                //    alert('Already taken');
                //}
                if ($(this).find('.threshhold').eq(0).text() == $("#txtThresholdDays").val()) {
                    alert('Already taken');
                }
            });

#Ruletype is id and .ruletype is class

Sunday, 9 February 2014

How to call a method in mvc4.0 using jquery ajax.

To call a method in mvc4.0 we can do it by using jquery ajax
$(document).ready(function () {
 $("#btnCreate").click(function () {
           $.ajax({
                 type: "GET",
                 url: '@Url.Action("GetRecords", "Status")',
                data: { strStatusValue: value },
                success: function (data) { },
                            error: function (error) {
                                $(".loading").hide();
                            }
                        })
            });
});
Note : Here i am getting value from from data "strStatusValue". using that we will get the records based on the value.

        [HttpPost]
        public JsonResult GetDetailsUsingId(string strEmailId)
        {

            DataSet ds = new DataSet();
            string procedureName = "getUserDataAccessTabs";
            SqlParameter[] Params = new SqlParameter[1];
            Params[0] = new SqlParameter("@userId", strEmailId);
            ds = DataAccess.SqlHelper.ExecuteDataset(ConnectionString,         CommandType.StoredProcedure,      procedureName, Params);
            return  Json(ds , JsonRequestBehavior.AllowGet);
        }

the above method will return the record based on "strStatusValue".

Here i used jquery ajax for partial rendering in the click event.

How to remove nulls in a table using jquery.

$('td:contains("null")').text('');

The above code replace nulls with ''.

Friday, 7 February 2014

how to view our web page center alignment in IE

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

IE is ok with this arrangement.

We have to add this at the top of the page.


<html>
<div style="width: 100%">
    <div style="width: 500px; margin: auto">

           </div>
</div>
The above is for content purpose.

Wednesday, 22 January 2014

How can i know what type of Sql Server version using in my machine

You can know by using the bellow commands:

1. SELECT @@VERSION---You can get the total details of your Sql server.

2. SELECT SERVERPROPERTY('Edition')---You can get only Edition name of your Sql server. like Standard,Developer etc.

3. SELECT SERVERPROPERTY('EditionID')---You can get only Edition IDof your Sql server. like -1534726760,-2117995310 etc.

Thursday, 25 July 2013

How to create a User control in asp.net ? & How to write methods and properties to user control in asp.net ?

Here first we have to create a user control. so, i will take a empty web application name it as "UserControl"and in this i add a user control (to add user control right click on "UserControl"  add new item 
in the left hand side click on "web" after that click on "web user control" name it as "DrpDwn.ascx"

Write the following code in .ascx page:

<table>
    <tr>
        <td>
            Select the country:
        </td>
        <td>
            <asp:DropDownList ID="Ddl_Country" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Ddl_Country_SelectedIndexChanged">
            </asp:DropDownList>
        </td>
    </tr>
    <tr>
        <td>
            Select the State:
        </td>
        <td>
            <asp:DropDownList ID="Ddl_State" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Ddl_State_SelectedIndexChanged">
            </asp:DropDownList>
        </td>
    </tr>
    <tr>
        <td>
            Select the City:
        </td>
        <td>
            <asp:DropDownList ID="Ddl_City" runat="server">
            </asp:DropDownList>
        </td>
    </tr>
</table>
Here i added above 3 dropdowns first one is for to select country,
second one is for to select state and last one is for getting list of cites
which you have selcted in the state dropdown.

write the following code in .ascx.cs page:

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Ddl_Country.DataSource = Country_Data();
                Ddl_Country.DataValueField = "Id";
                Ddl_Country.DataTextField = "Country_Name";
                Ddl_Country.DataBind();
                Ddl_Country.Items.Insert(0, "Select");
                Ddl_Country.Items[0].Value = "-1";
            }
        }

        public DataTable Country_Data()
        {
            DataTable dt_CountryData = new DataTable();
            dt_CountryData.Columns.Add("Id");
            dt_CountryData.Columns.Add("Country_Name");
            DataRow dr = dt_CountryData.NewRow();
            dr["Id"] = "1";
            dr["Country_Name"] = "India";
            dt_CountryData.Rows.Add(dr);
            DataRow dr1 = dt_CountryData.NewRow();
            dr1["Id"] = "2";
            dr1["Country_Name"] = "USA";
            dt_CountryData.Rows.Add(dr1);
            return dt_CountryData;

        }

        protected void Ddl_Country_SelectedIndexChanged(object sender, EventArgs e)
        {


            DataTable dt_StateData = new DataTable();
            dt_StateData.Columns.Add("Id");
            dt_StateData.Columns.Add("State_Name");
            dt_StateData.Columns.Add("Country_Id");
            DataRow dr = dt_StateData.NewRow();
            dr["Id"] = "1";
            dr["State_Name"] = "Andhrapradesh";
            dr["Country_Id"] = "1";
            dt_StateData.Rows.Add(dr);
            DataRow dr1 = dt_StateData.NewRow();
            dr1["Id"] = "2";
            dr1["State_Name"] = "Tamilnadu";
            dr1["Country_Id"] = "1";
            dt_StateData.Rows.Add(dr1);
            DataRow dr2 = dt_StateData.NewRow();
            dr2["Id"] = "3";
            dr2["State_Name"] = "California";
            dr2["Country_Id"] = "2";
            dt_StateData.Rows.Add(dr2);
            DataRow dr3 = dt_StateData.NewRow();
            dr3["Id"] = "4";
            dr3["State_Name"] = "Indiana";
            dr3["Country_Id"] = "2";
            dt_StateData.Rows.Add(dr3);

            DataView view = dt_StateData.DefaultView;
            view.RowFilter = "Country_Id =" + Ddl_Country.SelectedValue;
            view.Table.Columns.Remove("Country_Id");
            Ddl_State.DataSource = view.Table;
            Ddl_State.DataValueField = "Id";
            Ddl_State.DataTextField = "State_Name";
            Ddl_State.DataBind();
            Ddl_State.Items.Insert(0, "Select");
            Ddl_State.Items[0].Value = "-1";
            Ddl_City.ClearSelection();
            Ddl_City.Items.Clear();

        }

        protected void Ddl_State_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable dt_CityData = new DataTable();
            dt_CityData.Columns.Add("City_Id");
            dt_CityData.Columns.Add("City_Name");
            dt_CityData.Columns.Add("State_Id");
            DataRow dr = dt_CityData.NewRow();
            dr["City_Id"] = "1";
            dr["City_Name"] = "Visakhapatnam";
            dr["State_Id"] = "1";
            dt_CityData.Rows.Add(dr);
            DataRow dr1 = dt_CityData.NewRow();
            dr1["City_Id"] = "2";
            dr1["City_Name"] = "Hyderabad";
            dr1["State_Id"] = "1";
            dt_CityData.Rows.Add(dr1);
            DataRow dr2 = dt_CityData.NewRow();
            dr2["City_Id"] = "3";
            dr2["City_Name"] = "Vijayawada";
            dr2["State_Id"] = "1";
            dt_CityData.Rows.Add(dr2);

            DataRow dr3 = dt_CityData.NewRow();
            dr3["City_Id"] = "4";
            dr3["City_Name"] = "Coimbatore";
            dr3["State_Id"] = "2";
            dt_CityData.Rows.Add(dr3);
            DataRow dr4 = dt_CityData.NewRow();
            dr4["City_Id"] = "5";
            dr4["City_Name"] = "Madurai";
            dr4["State_Id"] = "2";
            dt_CityData.Rows.Add(dr4);
            DataRow dr5 = dt_CityData.NewRow();
            dr5["City_Id"] = "6";
            dr5["City_Name"] = "Tiruvarur";
            dr5["State_Id"] = "2";
            dt_CityData.Rows.Add(dr5);

            DataRow dr6 = dt_CityData.NewRow();
            dr6["City_Id"] = "7";
            dr6["City_Name"] = "Los Angeles";
            dr6["State_Id"] = "3";
            dt_CityData.Rows.Add(dr6);
            DataRow dr7 = dt_CityData.NewRow();
            dr7["City_Id"] = "8";
            dr7["City_Name"] = "Woodland";
            dr7["State_Id"] = "3";
            dt_CityData.Rows.Add(dr7);
            DataRow dr8 = dt_CityData.NewRow();
            dr8["City_Id"] = "9";
            dr8["City_Name"] = "San Diego";
            dr8["State_Id"] = "3";
            dt_CityData.Rows.Add(dr8);

            DataRow dr9 = dt_CityData.NewRow();
            dr9["City_Id"] = "10";
            dr9["City_Name"] = "lawrence";
            dr9["State_Id"] = "4";
            dt_CityData.Rows.Add(dr9);
            DataRow dr10 = dt_CityData.NewRow();
            dr10["City_Id"] = "11";
            dr10["City_Name"] = "south-bend";
            dr10["State_Id"] = "4";
            dt_CityData.Rows.Add(dr10);
            DataRow dr11 = dt_CityData.NewRow();
            dr11["City_Id"] = "12";
            dr11["City_Name"] = "Terre Haute";
            dr11["State_Id"] = "4";
            dt_CityData.Rows.Add(dr11);

            DataView CityView = dt_CityData.DefaultView;
            CityView.RowFilter = "State_Id =" + Ddl_State.SelectedValue;
            CityView.Table.Columns.Remove("State_Id");
            Ddl_City.DataSource = CityView;
            Ddl_City.DataValueField = "City_Id";
            Ddl_City.DataTextField = "City_Name";
            Ddl_City.DataBind();

        }

        public ArrayList SelectedText
        {
            get
            {
                ArrayList SelectedText = new ArrayList();
                if (Ddl_Country.SelectedIndex != -1 && Ddl_Country.SelectedIndex != 0)
                    SelectedText.Add(Ddl_Country.SelectedItem.ToString());
                else
                    SelectedText.Add(null);
                if (Ddl_State.SelectedIndex != -1 && Ddl_State.SelectedIndex != 0)
                    SelectedText.Add(Ddl_State.SelectedItem.ToString());
                else
                    SelectedText.Add(null);
                if (Ddl_City.SelectedIndex != -1)
                    SelectedText.Add(Ddl_City.SelectedItem.ToString());
                else
                    SelectedText.Add(null);
                return SelectedText;
            }
        }

        public ArrayList SelectedText
        {
            get
            {
                ArrayList selectedValues = new ArrayList();
                if (Ddl_Country.SelectedIndex != -1 && Ddl_Country.SelectedIndex != 0)
                    selectedValues.Add(Ddl_Country.SelectedValue.ToString());
                else
                    selectedValues.Add(null);
                if (Ddl_State.SelectedIndex != -1 && Ddl_State.SelectedIndex != 0)
                    selectedValues.Add(Ddl_State.SelectedValue.ToString());
                else
                    selectedValues.Add(null);
                if (Ddl_City.SelectedIndex != -1 )
                    selectedValues.Add(Ddl_City.SelectedValue.ToString());
                else
                    selectedValues.Add(null);

                return selectedValues;
            }
        }

 Here i created 2 properties for the user control like SelectedText, SelectedText. As per my requirement i added above.

Now take a new aspx page and name it as "page1.aspx"

write the code in aspx page

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="page1.aspx.cs" Inherits="UserControl_DrpDwn.page1" %>

<%@ Register TagPrefix="uc" TagName="Dropdown" Src="~/DrpDwn.ascx" %>
<!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">
    <script type="text/javascript">
      
    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc:Dropdown ID="uc1" runat="server" />
    </div>
    <div>
        <asp:Button ID="btnNames" Text="Click" runat="server"
            OnClick="btnNames_Click" /></div>
    <div>
        <asp:Label ID="lbltext" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>


 now go to code behind:

 protected void btnNames_Click(object sender, EventArgs e)
        {
            ArrayList Name = uc1.SelectedText;
            String strNames = null;
            foreach (var item in Name)
            {
                strNames += item + ",";
            }
            strNames = strNames.TrimEnd(',');
            lbltext.Text = strNames;




           ArrayList Name1 = uc1.SelectedValues;
            String strNames1 = null;
            foreach (var item in Name1)
            {
                strNames1+= item + ",";
            }
            strNames1 = strNames1.TrimEnd(',');
            label.Text = strNames1;
        }

you will get the properties.you can use here. i think so you guys learnt how to create a user control in Dotnet.
Thanks for reading.

Tuesday, 16 July 2013

How to display images using Evnet hadler in Dot Net(Images are stored in Sql server as )

To display an image in front end first we have to create an Handler. After creating handler it will display the image in aspx page.

First create an event handler (Go to website >>right click >>click on Add new item>>in the middle you will get a generic handler click on add.

after creating that write the following code :

using System;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;

public class ImageHandler : IHttpHandler
{

    string strcon = ConfigurationManager.AppSettings["EmployeeConnectionString"].ToString();
    public void ProcessRequest(HttpContext context)
    {
        int emp_Id = Convert.ToInt32(context.Request.QueryString["emp_Id"]);
        SqlConnection connection = new SqlConnection(strcon);
        connection.Open();
        SqlCommand command = new SqlCommand("select image from EmployeeDetails where emp_Id=" + emp_Id, connection);
        SqlDataReader dr = command.ExecuteReader();
        dr.Read();
        if (dr.HasRows)
        {
            if (dr[0] != DBNull.Value)
            {
                context.Response.BinaryWrite((Byte[])dr[0]);
                connection.Close();
                context.Response.End();
            }
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}

Note:
1)emp_Id  will get from aspx page.
2)Event handler will take the remaining things like conversion .

Now write the code in aspx.cs:

 SqlConnection connection = new SqlConnection(strcon);
            SqlCommand command = new SqlCommand("SELECT * from EmployeeDetails ", connection);
            SqlDataAdapter daimages = new SqlDataAdapter(command);
            DataTable dt = new DataTable();
            daimages.Fill(dt);
            gvImages.DataSource = dt;
            gvImages.DataBind();


Tuesday, 9 July 2013

how to upload a image into database




Byte[] imgByte = null;
        if (fileup.HasFile && fileup.PostedFile != null)
        {
            HttpPostedFile File = fileup.PostedFile;
            imgByte = new Byte[File.ContentLength];
            File.InputStream.Read(imgByte, 0, File.ContentLength);
        }
        empdetails.image = imgByte;

Sunday, 7 July 2013

How to get multiple tables using stored procedure Dynamically

USE [DuckCreek]
GO
/****** Object:  StoredProcedure [dbo].[Usp_Getreports]    Script Date: 07/08/2013 09:21:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- EXEC Usp_Getreports '2013-06-05 00:00:00.000', '2013-07-05 00:00:00.000', 'wc_'
ALTER procedure [dbo].[Usp_Getreports]
@Startdate date=null,
@Enddate date=null,
@Lob varchar(10)=null
as
begin
    declare @Inboundquery varchar(max)
    declare @Outboundquery varchar(max)
    declare @Failedpolicesquery varchar(max)
    declare @Reporttime varchar(max)
   
        set @Inboundquery = 'select ROW_NUMBER() OVER(ORDER BY TransactionDatatime DESC) AS SNo, * from ';
        set @Inboundquery = @Inboundquery +@Lob+'session s inner join '+@Lob+'data d on s.session_Id=d.session_Id inner join '+@Lob+'policy p on d.data_Id=p.data_Id where DATEADD(D, 0, DATEDIFF(D, 0, s.TransactionDatatime)) ';
        set @Inboundquery = @Inboundquery  + ' BETWEEN ''' + convert(varchar(10),@StartDate,110) + ''' AND ''' + convert(varchar(10),@EndDate,110) + ''''
       
       
        set @Outboundquery = 'select ROW_NUMBER() OVER(ORDER BY Record_Date DESC) AS SNo, Transaction_ID,Record_Date from ';
        set @Outboundquery = @Outboundquery +@Lob+'PROC_Trans_IDs where DATEADD(D, 0, DATEDIFF(D, 0, Record_Date))';
        set @Outboundquery = @Outboundquery + ' BETWEEN ''' + convert(varchar(10),@StartDate,110) + ''' AND ''' + convert(varchar(10),@EndDate,110) + ''''
       
        set @Failedpolicesquery = 'select ROW_NUMBER() OVER(ORDER BY TransactionDatatime DESC) AS SNo,Failedpolicy_Id,Session_Id, Error, TransactionId, TransactionDatatime from ';
        set @Failedpolicesquery = @Failedpolicesquery +@Lob+'FailedPolicies where DATEADD(D, 0, DATEDIFF(D, 0, TransactionDatatime)) ';
        set @Failedpolicesquery = @Failedpolicesquery + ' BETWEEN ''' + convert(varchar(10),@StartDate,110) + ''' AND ''' + convert(varchar(10),@EndDate,110) + ''''
       
        set @Reporttime='select convert(datetime,getdate())';
        exec (@Reporttime)
        print @Inboundquery;
        exec (@Inboundquery)
        exec (@Outboundquery)
        exec (@Failedpolicesquery)
       
       
end


Sunday, 30 June 2013

how to validate date using JavaScript

    <script type="text/javascript" language="javascript">
        function Compare() {

            var StartDate = document.getElementById('<%=TxtStartDate.ClientID %>').value;
            var EndDate = document.getElementById('<%=TxtEndDate.ClientID %>').value;
            var eDate = new Date(EndDate);
            var sDate = new Date(StartDate);
            if (sDate > eDate) {
                alert("Please ensure that the End Date is greater than or equal to the Start Date.");
                document.getElementById('<%=TxtEndDate.ClientID %>').focus();
                return false;
            }
            if (StartDate == "") {
                alert('Please select the start date ');
                document.getElementById('<%=TxtStartDate.ClientID %>').focus();
                return false;

            }
            if (EndDate == "") {
                alert('Please select the end date ');
                document.getElementById('<%=TxtEndDate.ClientID %>').focus();
                return false;
            }

            return true;
        }
        function ISspeical() {
            var charcode = window.event.keyCode;
            if (charcode == 31) {
                return false;
            }
            else
                return false;

        }
        function Clear() {
            var lbl = document.getElementById('<%=TxtEndDate.ClientID %>');
            lbl.value == "";
        }
    </script>