Hi guys...
Here is a simple javascript to display a confirm alert box and fetch its value..
you can simply perform other operations regarding the value that has been selected.
Hope this helps...
Ashutosh Jain - The .NET, C# Developer
you will find the Solutions to some programming problems that causes in ASP.NET, .NET, C#, SQL SERVER, ORACLE etc...
Sunday, May 8, 2011
Saturday, May 7, 2011
Javascript alert from codebehind
Hi Guys,
I have made a class which will allow to popup a message box easily in web pages.
Just include this class in your application.
"Alert.cs"
using System.Text;
using System.Web.UI;
///
/// A JavaScript alert
///
public static class Alert
{
///
/// Shows a client-side JavaScript alert in the browser.
///
/// The message to appear in the alert.
public static void Show(string message)
{
// Cleans the message to allow single quotation marks
string cleanMessage = message.Replace("'", "\\'");
string script = "";
// Gets the executing web page
Page page = HttpContext.Current.CurrentHandler as Page;
// Checks if the handler is a Page and that the script isn't allready on the Page
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
}
}
}
Now just call it from any page by using
Add.Show(Message that you want to print);
eg. Add.Show("Hello");
Hope this will help you and make your work easy...
Monday, April 25, 2011
.NET Date Format Conversion in Oracle Format
Hey guys...recently i was facing a small problem of converting the system date to the format that oracle accepts..Oracle date is format sensitive.
.NET has the format 'mm-dd-yyyy' and oracle has the format 'dd-MMM-yy'
So I passed the System.datetime.now as parameter _date.
Then we just need to do this..
string _str = _date.ToString("dd-MMM-yy");
_str has the value in format "dd-MMM-yy"
and to all of those who don't kow that oracle accepts date as a parameter in quotes.
eg. '21-APR-11'
I hope this helps...
Sunday, April 10, 2011
Removing Thousand and Decimal From a Numeric Field In Crystal Report
Hi guys,
Recently I faced a problem in crystal report where i had to convert a mobile no filed into the numeric field which should not have thousand and decimals in crystal report.
My field was coming from database. I just simply did this
Step -1) Right click on the field to which you want to perform the operation and click on Format object

Step-2) Now a format editor opens as shown in the figure and click on the button that is right alongside the "Display String"

Step - 3) Now opens the formula workshop...select the field in the first column from one of the three columns on the right side.
now at the bottom space write down the formula
Replace (cstr({Field Name},0,''),',' ,'')
all the thousand and decimals would be gone now..enjoy..

hope it will help you...!! :)
Friday, April 8, 2011
Multicolumn Primary key and Creating An Autonumber Field in Oracle
Hey guys...recently i faced this situation where i had to make two columns' combination a primary key in oracle and i found out the solution...
1 ) when creating a table
CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)
)
2) when you have to alter table
ALTER TABLE Persons
ADD CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)
This way you can make two columns's combination a primary key
and now to make a field auto number in oracle...
step 1) create a table
SQL> create table sample (
2 no number not null,
3 description varchar2(200),
4 constraint pk_sample primary key(no)
5 );
Table created.
step 2) Create a sequence object using the following code:
SQL> create sequence seq_sampleno
2 minvalue 1
3 start with 1
4 increment by 1;
Sequence created.
Step 3
Create a BEFORE INSERT trigger on sample table. Why BEFORE INSERT event? Because we need to take a sequence object’s value and then assign the value into a :new.no reference before Oracle actually insert a new record on sample table. Here is the code:
SQL> create or replace trigger tr_bi_sample
2 before insert on sample
3 for each row
4 begin
5 select seq_sampleno.nextval into :new.no from dual;
6 end;
7 /
Trigger created.
Step 4
Now, insert some new records into sample table using the following code:
SQL> insert into sample(description) values('First description');
1 row created.
SQL> insert into sample(description) values('Second description');
1 row created.
SQL> insert into sample(description) values('Third description');
1 row created.
To see the result, you can write the following code:
SQL> col no format 999 heading 'NO'
SQL> col description format A45 heading 'DESCRIPTION'
SQL> select * from sample;
Here is the result of that code:
NO DESCRIPTION
---- ---------------------------------------------
1 First description
2 Second description
3 Third description
I hope this helps you guys....!! :)
1 ) when creating a table
CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)
)
2) when you have to alter table
ALTER TABLE Persons
ADD CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)
This way you can make two columns's combination a primary key
and now to make a field auto number in oracle...
step 1) create a table
SQL> create table sample (
2 no number not null,
3 description varchar2(200),
4 constraint pk_sample primary key(no)
5 );
Table created.
step 2) Create a sequence object using the following code:
SQL> create sequence seq_sampleno
2 minvalue 1
3 start with 1
4 increment by 1;
Sequence created.
Step 3
Create a BEFORE INSERT trigger on sample table. Why BEFORE INSERT event? Because we need to take a sequence object’s value and then assign the value into a :new.no reference before Oracle actually insert a new record on sample table. Here is the code:
SQL> create or replace trigger tr_bi_sample
2 before insert on sample
3 for each row
4 begin
5 select seq_sampleno.nextval into :new.no from dual;
6 end;
7 /
Trigger created.
Step 4
Now, insert some new records into sample table using the following code:
SQL> insert into sample(description) values('First description');
1 row created.
SQL> insert into sample(description) values('Second description');
1 row created.
SQL> insert into sample(description) values('Third description');
1 row created.
To see the result, you can write the following code:
SQL> col no format 999 heading 'NO'
SQL> col description format A45 heading 'DESCRIPTION'
SQL> select * from sample;
Here is the result of that code:
NO DESCRIPTION
---- ---------------------------------------------
1 First description
2 Second description
3 Third description
I hope this helps you guys....!! :)
Monday, April 4, 2011
How to call Server Side function from Client Side Code using PageMethods in ASP.NET AJAX
You cannot call server-side code ‘directly’ from client-side code. That is because by design, the server side code executes at server side and client side code at the client. However there are some workarounds. To call serverside code from javascript, you will need to use AJAX, and the easiest way out, is to use the ASP.NET AJAX Extensions.
One option while using Microsoft ASP.NET AJAX is to call ASP.NET Web services (.asmx files) from the browser by using client script. The script can call a webservice containing server-based methods (Web methods) and invoke these methods without a postback and without refreshing the whole page. However this approach could be overkill sometimes, to perform the simplest of tasks. Moreover the logic needs to be kept in a separate .asmx file. We need something that is more ‘integrated’ with our solution.
The option we are going to use in this article involves PageMethods. A PageMethod is basically a public static method that is exposed in the code-behind of an aspx page and is callable from the client script. PageMethods are annotated with the [WebMethod] attribute. The page methods are rendered as inline JavaScript.
Let us explore PageMethods with an example. The example we will be discussing here may not be the best example to explain PageMethods, but it will give you an idea of how to call server side code from client side. In this example, we will be connecting to the Customers table in the Northwind database. We will have some textboxes which will accept the CustomerID and in turn return the Contact Name of that Customer. The method returning ContactName will be called whenever the textbox loses focus. We will be using the onblur event where a javascript code will take in the value(CustomerID) from the textbox. This javascript function will then call a PageMethod (server side code) which returns the ContactName without any page refresh.
I assume that you have downloaded and installed ASP.NET AJAX extensions for ASP.NET 2.0. If not, I would advise you to download the extensions from here and install it before moving ahead. At any point of time, if you find a difficulty in understanding the code, download the sample project attached with this article at the end.
One option while using Microsoft ASP.NET AJAX is to call ASP.NET Web services (.asmx files) from the browser by using client script. The script can call a webservice containing server-based methods (Web methods) and invoke these methods without a postback and without refreshing the whole page. However this approach could be overkill sometimes, to perform the simplest of tasks. Moreover the logic needs to be kept in a separate .asmx file. We need something that is more ‘integrated’ with our solution.
The option we are going to use in this article involves PageMethods. A PageMethod is basically a public static method that is exposed in the code-behind of an aspx page and is callable from the client script. PageMethods are annotated with the [WebMethod] attribute. The page methods are rendered as inline JavaScript.
Let us explore PageMethods with an example. The example we will be discussing here may not be the best example to explain PageMethods, but it will give you an idea of how to call server side code from client side. In this example, we will be connecting to the Customers table in the Northwind database. We will have some textboxes which will accept the CustomerID and in turn return the Contact Name of that Customer. The method returning ContactName will be called whenever the textbox loses focus. We will be using the onblur event where a javascript code will take in the value(CustomerID) from the textbox. This javascript function will then call a PageMethod (server side code) which returns the ContactName without any page refresh.
I assume that you have downloaded and installed ASP.NET AJAX extensions for ASP.NET 2.0. If not, I would advise you to download the extensions from here and install it before moving ahead. At any point of time, if you find a difficulty in understanding the code, download the sample project attached with this article at the end.
Step 1: Create an ASP.NET AJAX enabled website. Go to File > New > Website > ASP.NET AJAX-Enabled Web Site. Give the solution a name and location and click Ok.
Step 2: Drag and drop 2 labels and 4 textbox controls. We will be accepting the CustomerID from the user in the 2 textboxes and displaying the ‘ContactName’ in the other two textboxes. The textboxes that will display ‘ContactName’ has some properties set that will make it appear as a label without a border. Just set the BorderStyle=None, BorderColor=Transparent and ReadOnly=True. The markup will look similar to the following:
Wednesday, March 16, 2011
Oracle Date insert problem
Recently I was working with Oracle Database and I found that ASP.NET Datetime causes problem as a date parameter in insert query as Oracle only takes the date value as a parameter but ASP.NET passes the Date and the Time both.
So to solve this, as a simple method i used to split the date into string format by space character i.e. (' ')
So you get the first parameter of the string array as date and other two as time.
eg.
string [] _str = Convert.ToString(_date).Split(' ');
string _strQuery = "insert into "+_strTableName+" values ('"+_name+"',"+Convert.ToDouble(_mobileno)+",'"+_company+"','"+_purpose+"','"+_department+"','"+_contactperson+"','"+_city+"','"+_str[0]+"','"+_entryperson+"','"+_exitperson+"','"+_status+"')";
return (ExecuteScalarWithPara(_strQuery));
So its just as simple as that and you are done with this problem
So to solve this, as a simple method i used to split the date into string format by space character i.e. (' ')
So you get the first parameter of the string array as date and other two as time.
eg.
string [] _str = Convert.ToString(_date).Split(' ');
string _strQuery = "insert into "+_strTableName+" values ('"+_name+"',"+Convert.ToDouble(_mobileno)+",'"+_company+"','"+_purpose+"','"+_department+"','"+_contactperson+"','"+_city+"','"+_str[0]+"','"+_entryperson+"','"+_exitperson+"','"+_status+"')";
return (ExecuteScalarWithPara(_strQuery));
So its just as simple as that and you are done with this problem
Subscribe to:
Comments (Atom)