JQuery to Check User Name Availability from Database
Hi
try this example to use JQuery to Check User Name Availability from Database using the following steps :
1) Open MS SQL Server and create new database with contains table with the following schema
CREATE TABLE [dbo].[UserTable]( [UserName] [varchar](30) NOT NULL, [FirstName] [varchar](50) NOT NULL, [LastName] [varchar](50) NOT NULL, [Email] [varchar](70) NOT NULL, CONSTRAINT [PK_UserTable] PRIMARY KEY CLUSTERED ( [UserName] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]
2) Create Stored Procedure which will check if user exist or not in table
CREATE PROCEDURE CheckUserName( @UserName VARCHAR(50) ) AS BEGIN IF EXISTS (SELECT * FROM UserTable WHERE [UserName] = @UserName ) SELECT '1'; --user name already exist in database ELSE SELECT '0'; --user name does not exist in database END
3) Open VS2005 and create a new web site and add new web form
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="_Default" %> <head id="Head1" runat="server"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#<%=txtUserName.UniqueID%>").change(function() { var uname = $("#<%=txtUserName.UniqueID%>"); var msgbox = $("#status"); if (uname.val().length > 5) { $.ajax({ type: "POST", url: "Register.aspx/CheckUserName", data: "{'args': '" + uname.val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { if (msg.d == 'Available') { uname.removeClass("notavailablecss"); uname.addClass("availablecss"); msgbox.html('<img src="Images/yes.png"> <font color="Green"> Available </font>'); } else { uname.removeClass("availablecss"); uname.addClass("notavailablecss"); msgbox.html(msg.d); } } }); } else { uname.addClass("notavailablecss"); msgbox.html('<font color="#cc0000">User Name must be more than 5 characters</font>'); } }); }); </script> <style type="text/css"> body { font-family:Arial, Helvetica, sans-serif } #status { font-size:11px; margin:10px; } .availablecss { background-color:#CEFFCE; border:1px solid green; } .notavailablecss { background-color:#FFD9D9; border:1px solid red; } </style> </head> <body> <form id="form1" runat="server"> <br /> User Name : <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox> <span id="status"></span> </form> </body> </html>
4) In code behind add the following code
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [System.Web.Services.WebMethod] public static string CheckUserName(string args) { string returnValue = string.Empty; string conString = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString; SqlConnection sqlConn = new SqlConnection(conString); try { SqlCommand sqlCmd = new SqlCommand("CheckUserName", sqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.AddWithValue("@UserName", args.Trim()); sqlConn.Open(); int success = int.Parse((sqlCmd.ExecuteScalar().ToString())); if (success == 1) // User Name Not Available { returnValue = "<img src='Images/no.png'> <font color='#cc0000'><b>'" + args + "'</b> is already in use.</font></img>"; } else if (success == 0)//User_Name is available { returnValue = "Available"; } } catch { //Handle Error } finally { sqlConn.Close(); } return returnValue; } }
5) In web.config file add the connection string
<connectionStrings> <add name="MyConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" /> </connectionStrings>
after that run your application
Hope this helps
Good Luck.
Gridview Row Tooltip
Hi
try this example to Show Tooltip with Gridview Row
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"> <html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>" > <head runat="server"> <title>Untitled Page</title> <script language="javascript" type="text/javascript"> function ShowTooltip(name,address,city,state,phone1,fax) { // var Popup = document.getElementById("Popup"); document.getElementById("td0").innerText=name; document.getElementById("td1").innerText=address; document.getElementById("td2").innerText=city; document.getElementById("td3").innerText=state; document.getElementById("td4").innerText=phone1; document.getElementById("td5").innerText=fax; x = event.clientX + document.body.scrollLeft; y = event.clientY + document.body.scrollTop + 10; Popup.style.display="block"; Popup.style.left = x; Popup.style.top = y; } function HideTooltip() { Popup.style.display="none"; } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" /> <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" /> <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" /> <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" /> <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" /> <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [Address], [City], [Phone] FROM [Customers]"> </asp:SqlDataSource> </div> <div id="Popup"> <div style="BACKGROUND-COLOR: #003366"><b><center>Address</center></b></div> <div> <table width="100%" border=0 cellpadding=0 cellspacing=0> <tr> <td id=td0 align=left></td> </tr> <tr> <td id=td1 align=left></td> </tr> <tr> <td id=td2 align=left></td> </tr> <tr> <td id=td3 align=left></td> </tr> <tr> <td id=td4 align=left></td> </tr> <tr> <td id=td5 align=left></td> </tr> </table> </div> </div> </form> </body> </html>
and in code behind :-
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "ShowTooltip('" + DataBinder.Eval(e.Row.DataItem, "CompanyName").ToString() + "','" + DataBinder.Eval(e.Row.DataItem, "CustomerID").ToString() + "','" + DataBinder.Eval(e.Row.DataItem, "ContactName").ToString() + "','" + DataBinder.Eval(e.Row.DataItem, "Address").ToString() + "', '" + DataBinder.Eval(e.Row.DataItem, "City").ToString() + "','" + DataBinder.Eval(e.Row.DataItem, "Phone").ToString() + "');"); e.Row.Attributes.Add("onmouseout", "HideTooltip();"); } }
Hope this helps
Good Luck
Bind RadioButtonList with Image from Database
Hi
try this example to Bind RadioButtonList with Image from Database
Step1 :- Open MS SQL Server 2005 and create Database which contains Table called “Photo” whith the following fields
- Id –> (int) Primary key
- Title –> nvarchar(50)
- Pic –> nvarchar(20)
Step2 :- Open MS VS2005 and craete new website and add new folder called “images” which will contain all image that i will save it’s name with it’s Extension in my table
Step3 :- add new web page and add RadioButtonList control
Step4 :- in code behind of web page add the following code
public DataSet GetPhoto() { DataSet ds = new DataSet(); SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); SqlCommand comm = new SqlCommand(); comm.Connection = conn; comm.CommandText = "select * from Photo"; comm.CommandType = CommandType.Text; SqlDataAdapter adapter = new SqlDataAdapter(comm); adapter.Fill(ds); return ds; } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataSet photoDS = GetPhoto(); if (photoDS.Tables.Count > 0) { DataTable dt = photoDS.Tables[0]; foreach (DataRow row in dt.Rows) { ListItem item = new ListItem(); item.Text = "<img Width=\"100\" Height=\"100\" runat=\"Server\" src=\"images/" + row["Pic"].ToString() + "\" alt="+row["Title"].ToString()+" />"; item.Value = row["Id"].ToString(); RadioButtonList1.Items.Add(item); } //-- To Select First item in RadioButtonList RadioButtonList1.Items[0].Selected = true; RadioButtonList1.DataBind(); } } }
Step5:- in web.config add the connectionstring
<connectionStrings> <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /> </connectionStrings>
after that run the website
Hope this helps
Good Luck.
Validate Dropdownlist using Javascript
Hi
try this example to Validate Dropdownlist using Javascript
you can also check these posts to Validate DropdownList using Validator Controls
Validate DropdownList using Compare Validator
Validate DropdownList using Custom Validator
Validate DropdwonList with RequiredField Validator
<head> <script type ="text/javascript"> function CountryCheck() { var ddlCountry = document.getElementById ("<%=ddlCountry.ClientID%>"); var ddlCity = document.getElementById ("<%=ddlCity.ClientID%>"); var country = ddlCountry.options[ddlCountry.selectedIndex].value; var city = ddlCity.options[ddlCity.selectedIndex].value; if (country == "0") { alert("Please Select Country"); return false; } else { if (city == "0") { alert("Please Select City"); return false; } } return true; } </script> </head <asp:DropDownList ID="ddlCountry" runat="server"> <asp:ListItem Text ="----Select Country----" Value ="0"></asp:ListItem> <asp:ListItem Text ="US" Value ="1"></asp:ListItem> <asp:ListItem Text ="UK" Value ="2"></asp:ListItem> <asp:ListItem Text ="IN" Value ="3"></asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="ddlCity" runat="server"> <asp:ListItem Text ="----Select City----" Value ="0"></asp:ListItem> <asp:ListItem Text ="Mumbai" Value ="1"></asp:ListItem> <asp:ListItem Text ="Delhi" Value ="2"></asp:ListItem> <asp:ListItem Text ="Chennai" Value ="3"></asp:ListItem> </asp:DropDownList><asp:Button ID="Button3" runat="server" Text="Button" OnClientClick = "return CountryCheck();" /> </body>
Hope this helps
Good Luck
Validate FCKEditor Control
Hi
try this example to Validate FCKEditor Control using CustomValidator control
Your HTML Markup for FCKEditor:
<FCKeditorV2:FCKeditor ID="HTMLFCKeditor" runat="server" Height="400px" Width="100%"> </FCKeditorV2:FCKeditor> <asp:CustomValidator ID="CustomValidator2" runat="server" ValidationGroup="Invitation" ErrorMessage="Enter Message !" Display="Dynamic" ClientValidationFunction="ValidateFCKEditor"></asp:CustomValidator>
CustomValidator Javascript Function:
function ValidateFCKEditor(source, args) { var fckEditorClientID = document.getElementById('<%=HTMLFCKeditor.ClientID%>'); args.IsValid = FCKeditorAPI.GetInstance(fckEditorClientID.id).GetXHTML(true) != ""; }
Hope this helps
Good Luck.
Error: The task with the name Data Flow Task and the creation name “DTS.Pipeline.1” is not registered for use on this computer
I also ever experienced this problem. This problem occured probably, you use username and password to log on to your computer, so sql server need to verify the user who authorized to use the sql server service.. But sometimes sql server cannot redirect to the account, so we need to configure the user.
Here’s the step :
1. open sql server configuration mangager
2. choose sql server 2005 services
3. right click sql server integration services, choose properties
4. choose log on tab, select this account, enter your username and password which is used to log on your computer.
5. reopen the business intelligence studio. There you are, the data flow task component can work properly again.
finally, i found out how to solve this problem…
thanks to sulton..
Recent Comments