fishScript.com d
Home| Progetto| Web| Faq| Acronimi

Argomenti

Documenti pubblicabili:1120
Scripts:1282
Documenti non pubblicabili:162
Categorie tematiche:68
.Net
   |_C#
   |_Visual basic.net
   |_Asp.net
Active Server Pages
C++
Cascade Style Sheet
JavaScript
Mysql
Php
Xml
Java
   |_Java 2 Micro Edition
   |_Java server pages
   |_Java Servlet
Oracle
   |_PLSQL
PostgreSQL
Unix






PLSQL... Script: Esempio tipo VARRAY

Shell scripting... Script: Cercare e visualizzare file per dimensione

Un servizio Web XML è un'unità logica di applicazioni che fornisce dati e servizi ad altre applicazioni. Le applicazioni accedono ai servizi Web XML tramite protocolli Web universali e formati di dati quali HTTP, XML e SOAP.



La J2EE (Java 2 Enterprise Edition) è dedicata a tutti coloro che desiderano aggiungere il supporto della versione Enterprise di Java (ad esempio a Tomcat) e quindi le funzionalità avanzate come Enterprise JavaBeans etc.

Un servizio Web XML è un'unità logica di applicazioni che fornisce dati e servizi ad altre applicazioni. Le applicazioni accedono ai servizi Web XML tramite protocolli Web universali e formati di dati quali HTTP, XML e SOAP.

Asp.net

Home >Asp.net > Web controls and C# Sharp (Part II)

Stampa  Stampa


Web form

As the user is required to insert a new book, the page has to provide a form and some input field.
We are going to use an Asp.Net Web Control that basically provides:
  • Making sure the user inputs the mandatory data
  • Checking the conformity of the data (for example, integer type of data for the field price)
  • Activating the C# code necessary to save the data in the Access database

A web form is an Asp.Net technology to develop rapidly user interfaces. When the page is requested the .Net Framework engine produces an html and JavaScript code, tags and commands such as: text and button input or Onclick events, etc.
Indeed, web form and web controls are objects of .Net Framework installed on the web server, usually Microsoft IIS and then they are Runat=server.
Let's see the whole code for the web control:

<form id="myform" runat="server" >
<strong>Title:*<br /></strong>
<asp:TextBox id="title" Runat= "server"/><br />
<asp:RequiredFieldValidator id="rfvname" ControlToValidate="title"
ErrorMessage="*Mandatory"
Font-Bold= "True" Runat="server" /><br />
<strong><br />Author:<br /></strong>
<asp:TextBox id="author" Runat= "server"/><br />
<strong><br />Year:*<br /></strong>
<asp:TextBox id="year" size="4" maxlength="4" Runat="server"/><br />
<asp:RequiredFieldValidator
id="rfvyear"
ControlToValidate="year"
ErrorMessage="*Mandatory"
Font-Bold= "True"
Runat="server"/>
<asp:CompareValidator id="Compare1"
ControlToValidate="year"
EnableClientScript="True"
Type="Integer"
Operator="DataTypeCheck"
ErrorMessage="Incorrect type"
Font-Bold= "True"
runat="server"/>
<strong><br />Price:*<br /></strong>
<asp:TextBox id="price" size="3" maxlength="3" Runat="server"/>
<asp:RequiredFieldValidator
id="rfvprice"
ControlToValidate="price"
ErrorMessage="*Mandatory"
Font-Bold= "True"
Runat="server"/>
<asp:CompareValidator id="Compare2"
ControlToValidate="price"
EnableClientScript="True"
Type="Currency"
Operator="DataTypeCheck"
ErrorMessage="Incorrect type"
Font-Bold= "True"
runat="server"/>
<br />
<br />
<asp:Button id="PostBook" Text="Save data" OnClick="btnAddBook_Click" Runat="server" />
</form>


As you can see, some html is incapsulated in the web form.
Let's focus on some of the main properties of these web controls.
The TextBox control prints on video a textbox input field and identified the inputed value by an id.

<asp:TextBox id="title" Runat= "server"/>

The RequiredFieldValidator control provides validation of mandatory field, the property ControlToValidate identified by id the mandatory field.
The property ErrorMessage prints the message when the filed is left empty.

<asp:RequiredFieldValidator id="rfvname" ControlToValidate="title"
ErrorMessage="*Mandatory"
Font-Bold= "True" Runat="server" />


As you see the default font color is red:

Mandatory screen shot

The CompareValidator control provides logical validation of input data.
When the property EnableClientScript is set true, the Asp.net engine generates client code (JavaScript) so the validation is executed without send to the server another request. In our example, we think that for our hypothetical user appreciates time saving controls, we test positively the page with some browser non Microsoft (as Firefox), and then we decide to keep true this property...
The property Type declares the type of data allowed, in fact for the field price is Integer.
The property Operator if is set to DataTypeCheck to check the type of input data is conformant with the type declared.


<asp: CompareValidator id="Compare2"
ControlToValidate="price"
EnableClientScript="True"
Type="Currency"
Operator="DataTypeCheck"
ErrorMessage="Incorrect type"
Font-Bold= "True"
runat="server"/>


No doubt, the property ErrorMessage prints the message when the filed is left empty:

CompareValidator screen shot

The Button control is the last element in our form. It prints the button that, if pressed, (event OnCLick) submits the form and launches the C# btnAddBook_Click() function.

<asp:Button id="LinksPost" Text="Save data" OnClick="btnAddBook_Click" Runat="server" />


The output of this web form looks something like this:

Web form

Setting the Sql statement after the button click event

The function btnAddBook_Click()'duty is retrieve data from the web form, composing the insert sql statement and pass this string to the function ExecuteSqlCommand() that actually inserts the new row in the table.
As mentioned above, the function btnAddBook_Click() is activated by the button at the end of the web form.

private void btnAddBook_Click(object sender, System.EventArgs e)
{
// Declaring variables
string vtitle, vauthor,vyear,vdate,vprice;
// Reading, encoding and setting variables
vtitle = Server.HtmlEncode(title.Text);
vauthor = Server.HtmlEncode(author.Text);
vyear = Server.HtmlEncode(year.Text);
vprice = price.Text;

// Composing sql insert statement, Now() is going to record the insert time in the data_ins column
string sql = "INSERT INTO books (title,author,pyear,price,date_ins) "
+ " VALUES ('"+ vtitle+ "','"+ vauthor+"','"+ vyear +"',"+ vprice +",Now())";
// Now the sql string is passed to the ExecuteSqlCommand() function designed to execute not Query sql statement
ExecuteSqlCommand(sql);

// At last, for now, we simply reload the page
Response.Redirect("list_insert_books.aspx");
}

Executing a non query statement

A frequent solution to execute insert,delete,update command is developing a function good for any of this type sql statement.
So it is time for ExecuteSqlCommand()function 's code:

// ExecuteNonQuery for insert, delete, update sql command
private void ExecuteSqlCommand(string sql)
{
OleDbConnection conn = null;
try
{
// Connection: defining,creating,opening...
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=" + Server.MapPath("mydatabase.mdb"));
conn.Open();
//Creating an OleDbCommand command
OleDbCommand cmd =    new OleDbCommand(sql, conn);
//Finally executing the sql command
cmd.ExecuteNonQuery();
}
//the catch construct in case connection, query or else goes wrong prints the relative error message
catch (Exception e)
{
Response.Write(e.Message);
Response.End();
}
// always call Close when done reading.
finally
{
if (conn != null) conn.Close();
}
}


Now, it up to you developing further this script ... enjoying your programming!






Downloads:
bookstore.zip ( 12 KB)


Warning: include(ads/text468x15.html): failed to open stream: No such file or directory in D:\inetpub\webs\fishscriptcom\documents\view_document.php on line 131

Warning: include(): Failed opening 'ads/text468x15.html' for inclusion (include_path='.;C:\php\pear') in D:\inetpub\webs\fishscriptcom\documents\view_document.php on line 131

Tutorial
Costanti   [C#] 
Enum   [C#] 
Array dichiarazione, inizializzazione, stampa  [C#] 
Array caricamento e stampa attraverso un ciclo for  [C#] 
Array bidimensionali rettangolari inizialiazzazione e stampa  [C#] 
Oggetti (Object) valorizzati con ArrayList, Double, string, proprietà GetType  [C#] 
ArrayList proprietà count, metodo Add, Remove  [C#] 
Jagged array dichiarazione e inizializzazione  [C#] 
Proprietà validare il dato attraverso le proprieta  [C#] 
Overloading creare metodi con lo stesso nome e diverse implementazioni  [C#] 
Programma di cassa da console Tutorial per illustrare l'applicazione di costrutti fondamentali di programmazione come variabili, funzioni condizionali if/then Select/case, cicli, funzioni, oggetti ArrayList Funzioni principali e secondari  [Visual basic.net] 
Array stampa attraverso costrutto for/each  [C#] 
Web controls and C# Sharp (Part II) Saving data in an Access database using a web form   [Asp.net] 
Datagrid Delevoping a simple and quick datagrid to publish query's results  [Asp.net] 
Impostare variabili d’ambiente con .NET Framework 1.1   [C#] 
Script
Controlli e validazione   [Asp.net] 
If Then Costrutti fondamentali  [Visual basic.net] 
Importazione dei namespace Regole sintattiche: importazione delle classi  [Visual basic.net] 
Costrutto If Then Else Costrutti fondamentali  [Visual basic.net] 
Gestione degli errori 1 Iniziare a gestire errori e eccezioni  [Visual basic.net] 
Gestione degli errori 2 Dimostrazione   [Visual basic.net] 
Gestione istruzioni condizionali Costrutto Select/case (Esempio Applicazione da Console)  [Visual basic.net] 
HelloWorld! Iniziare con Visual Basic .Net  [Visual basic.net] 
Intercettare Input da Console Semplice esempio iterazione con l'utente  [Visual basic.net] 
Semplice programma da "console" Iniziare con Visual Basic .Net  [Visual basic.net] 
Leggere Input da Console Iniziare con Visual Basic .Net  [Visual basic.net] 
Lettura di un file di testo Operazioni sul file system: stream di un file e lettura del suo contenuto  [Visual basic.net] 
Lettura di un file Xml con l'oggetto XmlTextReader Parsing di file Xml attraverso i metodi dell'oggetto XmlTextReader  [Visual basic.net] 
Oggetto Date Stampare la data odierna  [Visual basic.net] 
Overloading accesso ad una funzione a secondo del tipo di valore Concetti di base  [Visual basic.net] 
Esercizi
Disegna alcuni tra i più utilizzati controlli di una form Costruire e compilare un form con il Designer di Visual Basic  [Visual basic.net] 
Cicli e operazioni su filesystem Attraverso un ciclo while creare quattro file .txt denominati 4 e i suoi quadrati (4.txt,16.txt,128.txt,2048.txt)  [Visual basic.net] 
File System Data una cartella esegue un copia di tutti i file ivi contenuti  [Visual basic.net] 
Comandi
Ricavare nome e percorso di un'applicazione   [C#] 
Postgres database uptime Last time database has been started (or restarted)  [.Net] 

signal Marco Magnani marcomagnani@fishscript.com



Cerca





Well-formedness is a new concept introduced by [XML]. Essentially this means that all elements must either have closing tags or be written in a special form (as described below), and that all the elements must nest properly.


Well-formedness is a new concept introduced by [XML]. Essentially this means that all elements must either have closing tags or be written in a special form (as described below), and that all the elements must nest properly.




Oracle... Definizioni: Schema


Shell scripting... Script: Looping samples



fishScript.Com is accessible by Mobile access technology as mobile phones, Palm and Pocket PC .

Nicoleta e Marco Magnani tutorial, examples, courses, esempi, corsi, esercizi, appunti vari Dottoressa Nicoleta Dragu Formatrice Docente Insegnante Mediatrice Culturale Dott. Marco Magnani Universita La Sapienza Roma Master Computer Science Hunter College New York , Data Base Administrator DBA oracle System architect

Last modified: 2017-11-30 amministratore@fishscript.comNico and Marco Magnani Software Production
Home|About this Site © 2003-2008 www.fishScript.com ®