Monday, 30 November 2015

How to open window dialog using javascript in asp.net

here is the code to open 1.       Open folders dialog


HTML Code:

  <div style="float: right; text-align: right; padding-right: 13px;">
        <a href="#" onclick="return openLocation();">Click me</a>
        <br />
        <input type="text" id="lblFolderPath" style="visibility: hidden" value="<%="file://"+Server.MachineName+"/"+pathToFolder.Replace("\\","/") %>" />
    </div>


Js code
function openLocation() {
            var pathFolder = $("#lblFolderPath").val();
            window.location = pathFolder;
            return false;

        }

How to read rows if repeater control in javascript

Here is the code may be helpful to you:

In repeater or any asp.net data control generates id as controlId+(_rowsNo) so that you can find all the controls row by row using javascript as below.

var repeaterControl = document.getElementById("dvRepeater");
    var tableControl = repeaterControl.getElementsByTagName("TABLE");
    for (var i = 0; i < tableControl.length; i++) {
        var correctAnswer = document.getElementById("ContentPlaceHolder1_rptID_txtCorrectAnswer_" + i).value;
        if (correctAnswer == "") {
            status = false;
            document.getElementById("ContentPlaceHolder1_rptID_txtCorrectAnswer_" + i).style.borderColor = "red";
        }
}

Monday, 18 March 2013

Show Online Users/Visitors in ASP.Net website



There are many ways to show online users/visitors in asp.net website.

Step:1 First, we need to add these lines in global.asax file



void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        Application["OnlineUsers"] = 0;
    }
 
    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started
        Application.Lock();
        Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
        Application.UnLock();
    }
 
    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
        Application.Lock();
        Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
        Application.UnLock();
    }

This will show that whenever distinct visitors opens our website in different browsers, and new session is created for him, our Online Users variable is increased in the global HttpApplicationState.

And when user closed browsers and does not click on any links then session will expires and Online Users variable is decreased.

Step:2 We need to enable SessionState and configure its mode alsoTo do that need to add these lines in web.config


  <system.web>
    <sessionState mode="InProc" cookieless="false" timeout="20" />
  </system.web>
 
  • In Proc mode stores session state value and variable in memory on the local web server. This mode is the only that supports Session_End event.
  • Timeout value (i.e in minutes) configure how long our sessions are keptalive. In this example, Timeout is set to 20 minutes that means, when the user click on some link on our website at least one time in 20 minutes, then users is considered as online but if they do not open any page or click on any link in 20 minutes then they are considered as offline.

So now we are done with the configuration steps. To show the number of online users/visitors, add these line in your aspx page

  Users/Visitors online<%Application["OnlineUsers"].ToString() %>

Saturday, 22 September 2012

Autocomplete using j query in asp.net code



Just put  below lines in head section of page :


 <script type="text/javascript">
                $(function () {
                    initializer();
                });
                var prmInstance = Sys.WebForms.PageRequestManager.getInstance();

                prmInstance.add_endRequest(function () {
                    //you need to re-bind your jquery events here
                    initializer();
                });
                function initializer() {
                    $("#<%=txtPartyNameSearch.ClientID%>").autocomplete('autoCmp.ashx')
            .result(function (event, data, formatted) {
                if (data) {
                    $("#<%= hidrefguagecode.ClientID %>").val(data[1]);
                }
                else {
                    $("#<%= hidrefguagecode.ClientID %>").val('-1');
                }
            });
                } 
</script>


Code for text box:




 <asp:TextBox ID="txtPartyNameSearch" runat="server" CssClass="TextBoxNew">
                                            </asp:TextBox>
                                            <asp:HiddenField ID="hidrefguagecode" runat="server" />


And add ashx file in your solution 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
namespace CS.WEB.UI
{
    /// <summary>
    /// Summary description for AutoCmp
    /// </summary>
    public class AutoCmp : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string prefixText = context.Request.QueryString["q"];
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConfigurationManager
                        .ConnectionStrings["ConnectionStr"].ConnectionString;
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "select PartyName from tblCustomerDetail where PartyName  LIKE '" + prefixText + "%'";

                    cmd.Parameters.AddWithValue("@SearchText", prefixText);
                    cmd.Connection = conn;
                    StringBuilder sb = new StringBuilder();
                    conn.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            sb.Append(sdr["PartyName"])
                                .Append(Environment.NewLine);
                        }
                    }
                    conn.Close();
                    context.Response.Write(sb.ToString());
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}


Tuesday, 18 September 2012

how to set auto serial number in asp.net gridview


Design view:







aspx code:

<asp:TemplateField HeaderText="S.No">
                       <ItemTemplate>
                       <%#Container.DataItemIndex+1 %>
                       </ItemTemplate>
 </asp:TemplateField>

-------------
------------

Thursday, 13 September 2012

How to Create Aspnetdb, Asp.net membership provider database using aspnet_regsql command - asp.net membership provider,role provider,profile provider



ASP.NET Membership

ASP.NET membership is a built in way to validate and store user credentials.And Asp.Net membership helps in user authentication in websites. We can implememt membershipprovider by Asp.net Forms authentication and Login control.

Purppose Of Membeship provider

1. Create new user with username and password.

2. Storing membership information in Sql Server,Active directory etc.

3.Authentication of users. By using ASP.NET login control,ASp.NET usercreation wizard etc implement complete authentication system.

4.Fascilitate role management etc

The database used to access membership database is normaly created with name ASPNETDB.MDF. Here is how to install ASPNETDB database


Creating ASPNETDB DATABASE in your SQLEXPRESS
ASPNETDB.MDF is membership provider database and is used for storing and retrieving
membership data from database and here we are going to see how to create membership provider database . The command used to create Aspnetdb.mdf is ASPNET_RegSQL.EXE


1.Start->Programs->Microsoft visual studio 2005->visual studio tools->Visual Studio 2005 command prompt. Type ASPNET_RegSQL.EXE in the visual Studio 2005 command prompt

2. A wizard with the heading " Welcome To The Asp.Net Sql Server Wizard " will be displayed. Here need to click Next

3. Next a wizard with " Select Setup Option " will displayed. Now we need to select setup option “Configure sql server for application purpose is default”. Select which one you wants and next.

4. A window with " Select Sql Server Database " Will be shown Now we need to select our sql server database. Here needs to set server, authentication type and database.
If select the default name"aspnetDb.mdf" will be selected. If you wants to modify existing database select that database.

5.Now A confirm will be displayed with heading "Confirm your Settings". Now check servername and database name and click next.

code to get one table schema into other table


            DataTable _dataTable = PrintData(1);
            // Copy from the results of a Select method.
            DataTable _DataTable2 = _dataTable.Clone();

            foreach (GridViewRow item in GVPendingDemand.Rows)
            {
                string lotId = GVPendingDemand.Rows[item.RowIndex].Cells[1].Text;
                CheckBox chk = item.FindControl("Chk") as CheckBox;
                if (chk.Checked)
                {
                    DataRow[] dr = _dataTable.Select("LotDemandId='" + lotId + "'");
                    if (dr.Length > 0)
                    {
                        for (int i = 0; i < dr.Length; i++)
                        {
                            _DataTable2.ImportRow(dr[i]);
                        }

                    }
                }
             
            }

Contact Us:

Email:

Vinodkumar434@gmail.com,
vinodtechnosoft@gmail.com

Skype Name:

vinodtechnosoft