Wednesday, December 29, 2010

Alert window Code

ScriptManager.RegisterClientScriptBlock(this.GetType(), "ClientScript", "window.alert('Vous ne pouvez pas supprimer un client utilisez le champ Statut');", True);"YourMessageHere");

write this query in at the end in submit button
Response.Write("<script language=javascript>alert('you have successfully posted your query');</script>");
...........................................

code Behind page of Controls
Alert.Show("You do not have write permission to this file");
.............................................

property of control write as....
OnclientClick=alert('submitted successfully..');

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

for form authentication on clicking Button:

------------------------------------------------------------------------------------
Alert and then redirect to next page
-----------------------------------
ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "alert('Employee added Successfully...!'); window.location.href = 'Add Employees.aspx';", true);
or
lbl_alert.Text = "<script>" + Environment.NewLine + "alert('Employee added Successfully...!');window.location('Add Employees.aspx');</script>";

http://www.velocityreviews.com/forums/t548336-show-alert-box-and-then-redirect.html




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

Thursday, December 23, 2010

Setting tab Focus in Selected location

1st  Method
----------------------------
WRITE THE CODE IN PAGE LOAD OR IN ANY EVENT LIKE BUTTON EVENT.........

Page.RegisterStartupScript("SetInitialFocus", "<script>document.getElementById('" + txtFirstName.ClientID + "').focus();</script>");
txtFirstName= is the  name of the control to focus

2ND Method
----------------------------

Easiest way to set a focus when web page is loaded
To set a focus when web page is loaded you can use a BODY onload event and javascript client code. Let say you have a web form with ID="Form1" with some controls, including a textbox named TextBox1. To set a focus to TextBox1 when page is loaded you can use this javascript code:
 
<body onload="javascript:document.Form1.TextBox1.focus();">

Saturday, December 18, 2010

Auto Increment No

public partial class Invoice_newinvoice : System.Web.UI.Page
{
   
    connection obj = new connection();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txt_invoiceno.Text=countinvoiceno().ToString();
            txt_custid.Text=countcustomerid().ToString();
            txt_invoicedate.Text = System.DateTime.Now.ToShortDateString();
        }

    }

    public string countinvoiceno()
    {
        string invno;
        obj.con.Open();
        obj.cmd1 = new SqlCommand("select 'IN'+cast(max(substring(invoiceno,3,3)+1)as varchar(50))from invoicemaster ", obj.con);
        obj.dr = obj.cmd1.ExecuteReader();
        obj.dr.Read();
        if (obj.dr.IsDBNull(0))
        {
            invno="IN1";
        }
        else
        {
            invno=obj.dr[0].ToString();
        }
        return invno;
        obj.con.Close();
    }
    public string countcustomerid()
    {
        obj.con.Close();
        obj.con.Open();
        obj.cmd1 = new SqlCommand("select 'CI'+cast(max(substring(invoiceno,3,3)+1)as varchar(50)) from customers", obj.con);
        string m ;
        obj.dr = obj.cmd1.ExecuteReader();
        obj.dr.Read();
        if (obj.dr.IsDBNull(0))
        {
            m = "CI1";
        }
        else
        {
            m = obj.dr[0].ToString();
        }
        return m;
        obj.con.Close();
    }


    protected void btn_submitinvoice_Click(object sender, EventArgs e)
    {
        obj.con.Open();
        obj.cmd = new SqlCommand("sp_invoiceinsert",obj.con);
        obj.cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13;
         
        p1 = new SqlParameter("@invoiceno",txt_invoiceno.Text);
        obj.cmd.Parameters.Add(p1);   
        p2 = new SqlParameter("@invoicedate",txt_invoicedate.Text);
        obj.cmd.Parameters.Add(p2);
        p10 = new SqlParameter("@customerid", txt_custid.Text);
        obj.cmd.Parameters.Add(p10);
        p4 = new SqlParameter("@totalamount",Convert.ToDecimal(txt_totalamt.Text));
        obj.cmd.Parameters.Add(p4);
        p5 = new SqlParameter("@paidamount", Convert.ToDecimal(txt_pamount.Text));
        obj.cmd.Parameters.Add(p5);
        p6 = new SqlParameter("@dueamount", Convert.ToDecimal(txt_damount.Text));
        obj.cmd.Parameters.Add(p6);
        p12 = new SqlParameter("@paymentmode", drdp_paymode.SelectedItem.Text);
        obj.cmd.Parameters.Add(p12);
        p13 = new SqlParameter("@taxtype", drdp_taxtype.SelectedItem.Text);
        obj.cmd.Parameters.Add(p13);
        p7 = new SqlParameter("@firstname",txt_fname.Text);
        obj.cmd.Parameters.Add(p7);       
        p8 = new SqlParameter("@address",txt_addr.Text);
        obj.cmd.Parameters.Add(p8);
        p11 = new SqlParameter("@phone", txt_phone.Text);
        obj.cmd.Parameters.Add(p11); 
        p9 = new SqlParameter("@email", txt_email.Text);
        obj.cmd.Parameters.Add(p9);
        obj.cmd.ExecuteNonQuery();
        obj.con.Close();
        Server.Transfer("/inventory/Invoice/newinvoice.aspx");

}
sql functions:
SUBSTRING(s,start,length):Returns a part of a string from String s starting from start position,where length is the no of chars to be picked...
ex:

SELECT SUBSTRING("HELLO",1,3) OUTPUT:HEL
CONVERTION FUNCTIONS:
Explicitly converts an expression of one datatype to another.. we has two conversion  functions CAST and CONVERT ,both provide similar functionality..
Example:
CAST Syntax:::
CAST(expression AS data_type[(length)])

Select CAST(10.6496 AS INT) output:10
Select CAST(10.6496 AS money) output:10 .3497
CONVERT Syntax
CONVERT(data_type[(length)],expression[,style(optional)])
select CONVERT(int,10.6496)
select CONVERT(Varchar(50),GETDATE())





Wednesday, December 15, 2010

open a new popup window in asp.net button click

1) <script type="text/javascript">
   function popWin()
   {
        window.open('http://msdn.microsoft.com','','');
   }
   </script>

2) call the above script in button click event or
in the properties of button  set
OnClientClick = popWin()
thats it.......
it open the url in new window

we can give it like this also..

<head>

  <script>
   function popWin(){
        window.open('http://msdn.microsoft.com', 'height=355,width=710,top=150,left=150,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,copyhistory=false', '');
   }
   </script>
    </head>



-----------------------------------------------------
or
--------------
<script type="text/javascript">
function popup()   
 {   
////paisalive popup     
 var url = "http://www.PaisaLive.com/register.asp?928456-4349429";                
  win= window.open(url,'welcome','widht=300,height=500,menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes,resizable=yes'); if (win)
 {
win.blur();
setTimeout('win.focus();',5000);
}
}
</script>

Thursday, December 9, 2010

SQL Stored Procedures

Stored procedures:
------------------------

INSERT

------------------
insert into dept values(13,'krishna',40000)
-------------
create proc sp_insert(@dno int,@dnm varchar(50),@dsal int)
as
insert into dept values(@dno,@dnm,@dsal)

exec sp_insert 13,'krishna',40000

DELETE
--------------------
delete from dept where dno=10
----------
create proc sp_delete(@dno int)
as
delete from dept where dno=@dno
exec sp_delete 10    

UPDATE
-------------
update dept set dname='xxx' dsal='1100' where dno=11
-------
create proc sp_update(@dno int,@dnm varchar(50),@ds int)
as
update dept set dname=@dnm,dsal=@ds where dno=@dno
exec sp_update 11,'venu',11000        


SELECT RETURN
-------------------
select * from dept
-------
create proc sp_selectreturn
as
select * from dept
return
exec sp_selectreturn  

SELECT
---------
create procedure sp_select(@dno int)
as
select dname,dsal from dept where dno=@dno
exec sp_select 10  

------------------------
ALTER COLUMN IN A TABLE
-->create table Users(UserId varchar(50),UserName varchar(50),UserRole varchar(50),ActiveUser int,permission varchar(50))
-->EXEC sp_rename 'Users.UserName', 'Password', 'column'


Syntax:EXEC sp_rename 'tablename.oldcolumn_name' 'newColumn_name'  'column'

-----------------------------------------
ADD NEW COLUMN IN A EXISTING TABLE


Ex:
alter table users add UserName varchar(50)


systax: 
Alter table table_name ADD new_columnName type(size)

                   

Friday, December 3, 2010

SQL UseFul Queries



REset the Identiy Column to Zero

==================================================
DBCC CHECKIDENT ( tbl_MOduleImages,RESEED,0)

Synatx :
DBCC CHECKIDENT (tbl_name,RESEED,0)

Adding Foreign Key To Tables
===================

GO
ALTER TABLE [dbo].[UserFavorite] WITH CHECK ADD CONSTRAINT [FK_UserFavorite_Users] FOREIGN KEY([UserID])
REFERENCES [dbo].[Users] ([EntityID])
GO

ALTER TABLE [dbo].[UserFavorite] CHECK CONSTRAINT [FK_UserFavorite_Users]
GO


========================================
Modify Table
Syntax to add new Column
alter table <tablename> ADD columnname <datatype> <width>
example
--------------
alter table dept add empname varchar(50)

Copy Data from table from Diferent Existing Database
===========================================

Drop table tbl_Property_Master
Note:Remove the Table if already Exists
select * into tbl_Property_Master from Property.dbo.Property_Master
Copy the data from table Property_Master in database Property to a new table tbl_Property_Master in another database

 viewing the items in grid view 
----------------------------------------
creating procedure
create proc sp_stockinview
as
select sno as SNO ,itemdesc as ITEM_DESCRIPTION,units as UNITS,ucost as UNIT_COST,total as TOTAL
from stockin
excuting procedure:
-----------------
exec sp_stockinview


appcode  Method
..............................
 public void viewStockin()
    {
        con.Open();
        cmd = new SqlCommand("sp_stockinview",con);
        cmd.CommandType = CommandType.StoredProcedure;
        dr=cmd.ExecuteReader();              
    } ...............................................


button click
protected void btn_viewadditems_Click(object sender, EventArgs e)
    {


        obj.viewStockin();
        GridView1.DataSource = obj.dr;
        GridView1.DataBind();
        obj.con.Close();
    }

AJAX Tool kit Contols Error

Getting problems when you upload your Ajax Control Toolkit powered website up to your server? Read on for a quick and easy solution!

Scenario

If you have added some of the Ajax Control Toolkit extenders into your website you will have probably tested them out on your local dev computer and marvelled at how easy it was to add some impressive eye candy to your site. Then, just when you think your work is done for the day and its time to put your new creation online you are hit with an error:
Could not load type 'System.Web.UI.ScriptReferenceBase' from assembly 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Well you don't need to worry too much because this time it is a really simple fix.

Quick Fix

If your site has just broken and you want to get it running quickly then the simplest solution is to change your <cc1:ToolkitScriptManager> tag to be just a plain <asp:ScriptManager> tag.
The ToolkitScriptManager is a wrapper control which provides the features of ScriptManager but also has a script combining feature to reduce the number of external javascript references generated by the toolkit.
So its as simple as taking your code
<cc1:ToolkitScriptManager runat="server" ... /> 
and changing it to
<asp:ScriptManager runat="server" ... /> 
(You might have a different prefix than cc1 but it doesn't matter).

The Real Fix

The real reason that your site is throwing the error is that the latest version of Ajax Control Toolkit expects to have a .net 3.5 SP1 runtime environment. The key bit here is the SP1 which means Service Pack 1.
To fix it you simply need to install the SP1 release which can be downloaded from here:
This needs to be run on your server so you will need remote desktop access to do this. This kind of control over your server is typically only available with dedicated servers or VPS virtual servers.
If you have a simple shared hosting package then you need to contact your web host and find out why they haven't upgraded yet. The SP1 release was a major upgrade which not only has many bug fixes included in it but also some great new features such as ASP.NET Dynamic Data. You can read all about the new features on the download link above.
In the worst case scenario where you cant get your host to upgrade and you cant move hosts because you are locked into a contract with them then you can at least fall back on the quick fix listed in the middle of this article to get your site running again.

http://runtingsproper.blogspot.com/2010/03/could-not-load-type.html

Tuesday, October 26, 2010

validating Phone number

Title : Indian Mobile No

Expression : ^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$
Description  : This expression is to validate indian mobile nos
Matches : 9836193498, +919836193498 ,9745622222
Non-Matches : +9197456222222 ,8745622222 ,9836193481
__________________________________________________________________________________
Title :Chennai Phone Numbers

Expression
: ^(0)44[\s]{0,1}[\-]{0,1}[\s]{0,1}2[\s]{0,1}[1-9]{1}[0-9]{6}$
Description :This expression will help you to match chennai telephone numbers. chennai bsnl telephone numbers will start from 2.
Matches : 044-26320244 | 04426320244
Non-Matches :044-12345678 | 123-12345678
 ------------------------------------------------------------------------------------------------------------
Refer for more Expressions:
http://regexlib.com/REDetails.aspx?regexp_id=2500
http://www.aspnetquest.com/feed-items/search.aspx?k=expression&p=9
http://www.dotnetspider.com/sites/1050/-Solutions-Tips.aspx

Tuesday, October 5, 2010

Elminatinig duplicate values in databse table

 emp1 --->temporary empty table
dept----> original table with columns and rows
we use distinct key word to eliminate duplicate values
1.move the records from dept to a temporary table emp1 
     select distinct * into emp1  from dept

2 delete the original table dept
     drop table dept

3. move emp1 records to dept table
     select * into dept from emp1

4.check the original table
    select * from dept


Browser asking username & password

problem of asking to type username and passoword for http://localhost. try this solution as mentioned below :
1. Open firefox and type in the address bar about:config
2. type ntlm in the textbox.
3. Double click on network.automatic-ntlm-auth.trusted-uris and type localhost there.
4. Click on OK.

You are done.
for Internet Explorer follow these steps:

The Log in Pop up is due to a setting in your IE Browser.
In your IE Browser:
1. Go to the Top menu "Tools" -> "Internet Options".
2. Then choose the "Advanced" Tab.
3. Then Scroll all the way down and "Uncheck" the Checkbox corresponding to "Enable Integrated Windows Authentication".
4. Then Click the button that says "Apply" and then "OK".
5. Close the browser and in a new browser try http://localhost.

for IIS SERVER  follow these steps:

1.start->run-> type inetmgr 
2 click on .internet nformation services-->Local Computer-->web sites-->default websites->right click and goto properties
3. select Directory Security Tab-->under anonymous access and authentication control --> click on edit button.
4.Check The Anonymous Access->ok
or
4. uncheck the Integrated Windows Authentication--.> ok-->ok

thats it ! u r done