Tuesday, October 9, 2012

CustomValidator example in asp.net

In this example, we will simply check the length of the string in the TextBox. This is a very basic and that useful example, only made to show you how you may use the CustomValidator.

Custom text:
<asp:textbox id="txtCustom" runat="server">
<asp:customvalidator controltovalidate="txtCustom" errormessage="The text must be exactly 8 characters long!" id="cusCustom" onservervalidate="cusCustom_ServerValidate" runat="server">

</asp:customvalidator></asp:textbox>


As you can see, it's pretty simple. The only unknown property is the onservervalidate event. It's used to reference a method from CodeBehind which will handle the validation. Switch to our CodeBehind file and add the following method:

protected void cusCustom_ServerValidate(object sender, ServerValidateEventArgs e)
{
    if(e.Value.Length == 8)
        e.IsValid = true;
    else
        e.IsValid = false;
}
This is very simple. The validator basically works by setting the e.IsValid boolean value to either true or false. Here we check the e.Value, which is the string of the control being validated, for it's length. If it's exactly 8 characters long, we return true, otherwise we return false.

IDM fake key serial number block problem?

Solutioin;-
 
1. Exit IDM from the taskbar before entering the serial.
2. Disconnect active connections to the internet.
3. Then go to the directory C:\Windows\system32\drivers\etc and locate the file 'hosts'
4. Open the "hosts" file with "notepad".
5. on the last line enter the following address as shown and save.

127.0.0.1 www.internetdownloadmanager.com




6. Now, again enter the "fake serial" and wait for few seconds.
7. your IDM is registered again.

Thursday, October 4, 2012

Create Procedure in Sql Server Step by Step

create new demo database
CREATE DATABASE demo
use demo Database
USE demo
create new table
CREATE TABLE demoTest
(
 id INT,
 NAME VARCHAR(30),
 ADDR VARCHAR(50)
 )

create Procedure for inserting data into demoTest Table.
CREATE PROC ins_DemoTest
@id  INT,@name  VARCHAR(30),@addr  VARCHAR(30)
AS 
BEGIN
 INSERT INTO demoTest
 (
  id,
  NAME,
  ADDR
 )
 VALUES
 (
  @id,
  @name,
  @addr
 )
END
execute procedure
EXEC ins_DemoTest 1,'Aditya','New Delhi'
EXEC ins_DemoTest 2,'Abhishek','Lucknow'
EXEC ins_DemoTest 3,'Akhilesh','Greater Noida'
EXEC ins_DemoTest 4,'Abhi','Noida'
select data from Table
SELECT * FROM demoTest
id NAME ADDR
1 Aditya New Delhi
2 Abhishek Lucknow
3 Akhilesh Greater Noida
4 Abhi Noida

Parameterized Sql Query in Asp.net

Dim ds As DataSet = New DataSet()
        Dim param As SqlParameter = New SqlParameter("@user_code", SqlDbType.VarChar, 4)
        param.Value = Convert.ToString("0016")
        Const sqlstr As String = "select sectors.sector_code,sector_name   from user_sectors inner join sectors on user_sectors.sector_code = sectors.sector_code  where user_code = @user_code  and sectors.sector_code not in ('z')"
        Dim da As SqlDataAdapter = New SqlDataAdapter(sqlstr, _con)
        da.SelectCommand.Parameters.Add(param)
        da.Fill(ds)
        ddl.DataValueField = "sector_code"
        ddl.DataTextField = "sector_name"
        ddl.DataSource = ds.Tables(0)
        ddl.DataBind()


 

About Me

 

Aditya Pratap Singh

Programmer  :   CyberQ India Counsalting Pvt. Ltd.

Qualification :  MCA (UPTU-2011)

Exp  :                       1.6 yrs

Mo. :                        9911690423

Email:                   adityapratapsingh002@gmail.com

Working Area: C#,VB,Asp.net,SqlServer,JavaScript,JQuery