asp.net Client Callbacks using csharp

30. November 2009

To implement client callbacks you need to do some work both on server side as well as client side.

On server side, you need to:

  1. Implement ICallBackEventHandler in the page, that you want to use callbacks in. It have two methods i.e. RaiseCallbackEvent and GetCallbackResults
  2. Provide implementation for RaiseCallBackEvent, this is the method is invoked by the client to perform callbacks. This method accepts string as an argument.
  3. Provide implementation for GetCallbackResults, this method is invoked by the server, to process the request and return the results to the client as a string
  4. Retrieve a reference of a client side function (Using ClientScript.GetCallbackEventReference method), this function will be invoked as the result of server side processing, and it can be used to process any results coming back from server
  5. Register a client side script, using Page.ClientScript.RegisterClientScriptBlock method, that will make a call to the server. 

On ClientSide, you need to:

  1. Implement the function that you provided as an argument in step 4 above
  2. Call the function you registered in step 5 above, on a client side event.
  3.  

     

cs page

public string ScriptRef; //Script reference that will be used on client side
public string Result;
protected void Page_Load(object sender, EventArgs e)
{
//ScriptRef = ClientScript.GetCallbackEventReference(this, "eventArgs", "processSuccess", "context", "processError", true);
}

void ICallbackEventHandler.RaiseCallbackEvent(string eventArgs)
{
string[] res = eventArgs.Split('#');
Result = (int.Parse(res[0].ToString()) + int.Parse(res[1].ToString())).ToString();
}
string ICallbackEventHandler.GetCallbackResult()
{
return Result;
}
A = <asp:TextBox ID="txtA" runat="server"></asp:TextBox><br />
B = <asp:TextBox ID="txtB" runat="server"></asp:TextBox><br />
<br /><br />
<asp:Button ID="btnCalculate" runat="server" Text="Sum A and B Now" OnClientClick='CallBack(); return false;' />
<br /><br />
A + B = <asp:TextBox ID="txtC" runat="server"></asp:TextBox>



</div>
<script type="text/javascript" language="javascript">
function CallBack()
{
var a = document.getElementById("<%=txtA.ClientID%>").value;
var b = document.getElementById("<%=txtB.ClientID%>").value;
var eventArgs = a + '#' + b;
var context = 'Page1';
WebForm_DoCallback('__Page',eventArgs,processSuccess,context,processError,true)
}

function processSuccess(returnValue, context)
{
document.getElementById("<%=txtC.ClientID%>").value = returnValue;
}

function processError(returnValue, context)
{
alert("Callback Error: " + returnmessage + ", " + context);
}

</script>

<script type="text/javascript">
//<![CDATA[

WebForm_InitCallback();
//]]>
</script>


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, asp.net 4.0

Client-Callback Implementation using asp.net csharp (c#)

30. November 2009

aspx page code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html > <head id="Head1" runat="server"> <title>Client Callback Example</title> <script type="text/ecmascript"> function LookUpStock() { var lb = document.getElementById("ListBox1"); var product = lb.options[lb.selectedIndex].text; CallServer(product, ""); } function ReceiveServerData(rValue) { document.getElementById("ResultsSpan").innerHTML = rValue; } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ListBox ID="ListBox1" Runat="server"></asp:ListBox> <br /> <br /> <button type="Button" onclick="LookUpStock()">Look Up Stock</button> <br /> <br /> Items in stock: <span id="ResultsSpan" runat="server"></span> <br /> </div> </form> </body> </html>
cs page code

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ClientCallback : System.Web.UI.Page,
     System.Web.UI.ICallbackEventHandler
{
    protected System.Collections.Specialized.ListDictionary catalog;
    protected String returnValue;
    protected void Page_Load(object sender, EventArgs e)
    {
        String cbReference =
            Page.ClientScript.GetCallbackEventReference(this,
            "arg", "ReceiveServerData", "context");
        String callbackScript;
        callbackScript = "function CallServer(arg, context)" +
            "{ " + cbReference + ";}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
            "CallServer", callbackScript, true);

        catalog = new System.Collections.Specialized.ListDictionary();
        catalog.Add("monitor", 12);
        catalog.Add("laptop", 10);
        catalog.Add("keyboard", 23);
        catalog.Add("mouse", 17);

        ListBox1.DataSource = catalog;
        ListBox1.DataTextField = "key";
        ListBox1.DataBind();

    }

    public void RaiseCallbackEvent(String eventArgument)
    {
        if (catalog[eventArgument] == null)
        {
            returnValue = "-1";
        }
        else
        {
            returnValue = catalog[eventArgument].ToString();
        }
    }
    public String GetCallbackResult()
    {
        return returnValue;
    }
}

 

 

 


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, Architecture, asp.net, asp.net 4.0

Alter table:add, delete ,modify(rename ) using query in ms sql 2005 and ms sql 2008

29. November 2009

The ALTER TABLE statement allows you to rename an existing table. It can also be used to add, modify, or drop a column from an existing table.

Renaming a table

The basic syntax for renaming a table is:

ALTER TABLE table_name
RENAME TO new_table_name;

For example:

ALTER TABLE AamirHasan
RENAME TO studentacad;

This will rename the AamirHasan table to studentacad.

Adding column(s) to a table

Syntax #1

To add a column to an existing table, the ALTER TABLE syntax is:

ALTER TABLE table_name
ADD column_name column-definition;

For example:

ALTER TABLE AamirHasan
ADD AamirHasan_name varchar2(50);

This will add a column called AamirHasan_name to the AamirHasan table.

Syntax #2

To add multiple columns to an existing table, the ALTER TABLE syntax is:

ALTER TABLE table_name
ADD ( column_1 column-definition,
column_2 column-definition,
...
column_n column_definition );

For example:

ALTER TABLE AamirHasan
ADD ( AamirHasan_name varchar2(50),
city varchar2(45) );

This will add two columns (AamirHasan_name and city) to the AamirHasan table.

Modifying column(s) in a table

Syntax #1

To modify a column in an existing table, the ALTER TABLE syntax is:

ALTER TABLE table_name
MODIFY column_name column_type;

For example:

ALTER TABLE AamirHasan
MODIFY AamirHasan_name varchar2(100) not null;

This will modify the column called AamirHasan_name to be a data type of varchar2(100) and force the column to not allow null values.

Syntax #2

To modify multiple columns in an existing table, the ALTER TABLE syntax is:

ALTER TABLE table_name
MODIFY ( column_1 column_type,
column_2 column_type,
...
column_n column_type );

For example:

ALTER TABLE AamirHasan
MODIFY ( AamirHasan_name varchar2(100) not null,
city varchar2(75) );

This will modify both the AamirHasan_name and city columns.

Drop column(s) in a table

Syntax #1

To drop a column in an existing table, the ALTER TABLE syntax is:

ALTER TABLE table_name
DROP COLUMN column_name;

For example:

ALTER TABLE AamirHasan
DROP COLUMN AamirHasan_name;

This will drop the column called AamirHasan_name from the table called AamirHasan.

Rename column(s) in a table
(NEW in Oracle 9i Release 2)

Syntax #1

Starting in Oracle 9i Release 2, you can now rename a column.

To rename a column in an existing table, the ALTER TABLE syntax is:

ALTER TABLE table_name
RENAME COLUMN old_name to new_name;

For example:

ALTER TABLE AamirHasan
RENAME COLUMN AamirHasan_name to sname;

This will rename the column called AamirHasan_name to sname.

Acknowledgements: Thanks to Dave M., Craig A., and Susan W. for contributing to this solution!

Practice Exercise #1:

Based on the departments table below, rename the departments table to depts.

CREATE TABLE departments
( department_id number(10) not null,
department_name varchar2(50) not null,
CONSTRAINT departments_pk PRIMARY KEY (department_id)
);

Solution:

The following ALTER TABLE statement would rename the departments table to depts:

ALTER TABLE departments
RENAME TO depts;


Practice Exercise #2:

Based on the employees table below, add a column called salary that is a number(6) datatype.

CREATE TABLE employees
( employee_number number(10) not null,
employee_name varchar2(50) not null,
department_id number(10),
CONSTRAINT employees_pk PRIMARY KEY (employee_number)
);

Solution:

The following ALTER TABLE statement would add a salary column to the employees table:

ALTER TABLE employees
ADD salary number(6);


Practice Exercise #3:

Based on the customers table below, add two columns - one column called contact_name that is a varchar2(50) datatype and one column called last_contacted that is a date datatype.

CREATE TABLE customers
( customer_id number(10) not null,
customer_name varchar2(50) not null,
address varchar2(50),
city varchar2(50),
state varchar2(25),
zip_code varchar2(10),
CONSTRAINT customers_pk PRIMARY KEY (customer_id)
);

Solution:

The following ALTER TABLE statement would add the contact_name and last_contacted columns to the customers table:

ALTER TABLE customers
ADD ( contact_name varchar2(50),
last_contacted date );


Practice Exercise #4:

Based on the employees table below, change the employee_name column to a varchar2(75) datatype.

CREATE TABLE employees
( employee_number number(10) not null,
employee_name varchar2(50) not null,
department_id number(10),
CONSTRAINT employees_pk PRIMARY KEY (employee_number)
);

Solution:

The following ALTER TABLE statement would change the datatype for the employee_name column to varchar2(75):

ALTER TABLE employees
MODIFY employee_name varchar2(75);


Practice Exercise #5:

Based on the customers table below, change the customer_name column to NOT allow null values and change the state column to a varchar2(2) datatype.

CREATE TABLE customers
( customer_id number(10) not null,
customer_name varchar2(50),
address varchar2(50),
city varchar2(50),
state varchar2(25),
zip_code varchar2(10),
CONSTRAINT customers_pk PRIMARY KEY (customer_id)
);

Solution:

The following ALTER TABLE statement would modify the customer_name and state columns accordingly in the customers table:

ALTER TABLE customers
MODIFY ( customer_name varchar2(50) not null,
state varchar2(2) );


Practice Exercise #6:

Based on the employees table below, drop the salary column.

CREATE TABLE employees
( employee_number number(10) not null,
employee_name varchar2(50) not null,
department_id number(10),
salary number(6),
CONSTRAINT employees_pk PRIMARY KEY (employee_number)
);

Solution:

The following ALTER TABLE statement would drop the salary column from the employees table:

ALTER TABLE employees
DROP COLUMN salary;


Practice Exercise #7:

Based on the departments table below, rename the department_name column to dept_name.

CREATE TABLE departments
( department_id number(10) not null,
department_name varchar2(50) not null,
CONSTRAINT departments_pk PRIMARY KEY (department_id)
);

Solution:

The following ALTER TABLE statement would rename the department_name column to dept_name in the departments table:

ALTER TABLE departments
RENAME COLUMN department_name to dept_name;


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, SQL 2005 & 2008

ms sql list of all object in database

29. November 2009

SYSOBJECTS has a list of the objects.
XTYPE defines what it is.

  • C = Check constraint
  • D = Default constraint
  • F = Foreign key
  • L = Log
  • P = Stored procedure
  • PK = Primary key
  • RF = Replication filter
  • S = System table
  • TR = Trigger
  • U = User table
  • UQ = Unique constraint
  • V = View
  • X = Extended stored procedure

  1. USE master;
  2. go
  3. SELECT SUBSTRING(name,1,40) AS 'Object',
  4.        crdate AS 'Created',
  5.        CASE xtype
  6.        WHEN 'C' THEN 'Check constraint'
  7.        WHEN 'D' THEN 'Default constraint'
  8.        WHEN 'F' THEN 'Foreign key'
  9.        WHEN 'L' THEN 'Log'
  10.        WHEN 'P' THEN 'Stored procedure'
  11.        WHEN 'PK' THEN 'Primary key'
  12.        WHEN 'RF' THEN 'Replication filter stored procedure'
  13.        WHEN 'S' THEN 'System table'
  14.        WHEN 'TR' THEN 'Trigger'
  15.        WHEN 'U' THEN 'User table'
  16.        WHEN 'UQ' THEN 'Unique'
  17.        WHEN 'V' THEN 'View'
  18.        WHEN 'X' THEN 'Extended stored procedure'
  19.       END AS 'Type'
  20. FROM sysobjects
  21. WHERE xtype in ('C','D','F','L','P','PK','RF','S','TR','U','UQ','V','X')
  22. ORDER BY xtype, name;


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, SQL 2005 & 2008

sql 2005 common tables

29. November 2009

with MyCTE(x)
as
(select x='hello')
select x from MyCTE

 

with MyCTE(x)
as
(
select top 10 x = id from sysobjects
)
select x, maxx = (select max(x) from MyCTE), pct =
100.0 * x / (select sum(x) from MyCTE)
from MyCTE

 


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, SQL 2005 & 2008



User Name: Guest

Your Ip: 38.107.191.91
Time: