Controls Wizard Multiview File Upload Jsrunningtime2rtf

download Controls Wizard Multiview File Upload Jsrunningtime2rtf

If you can't read please download the document

Transcript of Controls Wizard Multiview File Upload Jsrunningtime2rtf

1.File Upload Control:

protected void BTnUpload_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { try { FileUpload1.SaveAs("D:\\upload\\" + FileUpload1.FileName); Label1.Text = "file uploaded
" + "File memory is:" + FileUpload1.PostedFile.ContentLength + "KB" + "
" + "format of the file is: " + FileUpload1.PostedFile.ContentType; } catch (Exception ex) { Label1.Text = ex.Message.ToString(); } } else{ Label1.Text = "u have not specified a file"; } }

2.WIZARD CONTROL

Net work Enabled Technology To Work on

Internet Sun Micro systems Product,with Enhanced Features J2EE,J2me Advanced Java Core Java!!!!!!!! ERP Systems Database Applications Finance development etc Sun Solaris product Command based Netwrking solutions on LAN NOTE:To make the look more color ful u can use Autoformat from the smart tag as shown in pic.

3.MultiView control:

Desigin Code: Go To Arsh By 10am lakdikapool by 3pm

Go To home by evening 6pm

Cs file code:------Page load code here---protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) {

MultiView1.ActiveViewIndex = 0;

//this indicates that multivew controls steps index should start with 0 index(i.e //1st step) when the page is loaded for the first time

} } Buttons of Multivew steps with click events. protected void vbtn1_Click(object sender, EventArgs e) { MultiView1.ActiveViewIndex += 1; if (MultiView1.ActiveViewIndex >= 2) { vbtn3.Visible = false; } }

4.Adrotator control: To create ad we should first add a xml file using add new items templateXML file( filename is: XMLFile.xml) ~/images/3.jpg http://www.contoso-ltd.com Ad for Contoso, Ltd. Web site 0.125 ~/images/lady.jpg http://www.asp.net Ad for ASP.NET Web site 0.125

Design code: Here add the xml datasource

Javascript: 5.SIMPE CONFIRM ALERT MESSAGE BOX USING JAVASCRIPT:

function show_alert() { alert("this is alert box"); }

5.Client side validation for Textboxes:Design

function validate() {

var tbu=document.getElementById("tb_user"); var tbp=document.getElementById("tb_pwd"); if(tbu.value=="") { alert("plz enter the username"); return false; } else if(tbp.value=="") { alert("plz enter password"); return false; } }

Design code:Here just call the javascript function onclient click event

Note:if u take separate .js file using add new item template then place src attribute inside script tag and give function name. Eg:

6.Onmouse over and on mousemove events using Javascript This example will show u when the mouseover and mouse out events are fired on he image control of HTML. JAVA SCRIPT CODE: function omv() { document.b.src="img/w1_enlarge46.jpg"; } var i; function omo() { document.b.src="img/w2_enlarge12.jpg"; }

Design code:

7.Image Rotation(animation) Using Javascript: Javascript code: var image=""; var banners=0; function loadbanners() { if (banners==1) { image="images/w1_enlarge46.jpg"; } if (banners==2) { image="images/w2_enlarge12.jpg"; } if (banners==3) { image=" images/w2_enlarge14.jpg"; } if (banners==4) { image=" images/wall1.jpg"; } } function cycle() { if (++banners > 4) banners=1; loadbanners(); document.getElementById("banner1").src =image; window.setTimeout('cycle();',250); }

8.Showing Running Time & working with various events Using Javascript:

function startTime() { var today=new Date(); var h=today.getHours(); var m=today.getMinutes(); var s=today.getSeconds(); var d=today.getDate(); //h=hour12(h) //adding a zero infront of numbers less than 10 //m=checkTime(m);

//s=checkTime(s); document.getElementById('label').innerHTML=h+":" +m+ ":"+s+"
todays date is:&nbsp &nbsp &nbsp "+d; t=setTimeout('startTime()',500) } //if we want to place a zero before the seconds(when secods become single digited) //function checkTime(i) //{ //if(i12) //{ //i= "0" + i-12; //} //return i; //}

State management Ex: Cookies:Cookiesender.aspx Design

Buton click code(Cookiesender.aspx): protected void Button1_Click(object sender, EventArgs e) { HttpCookie cName = new HttpCookie("Name"); cName.Value = txt_name.Text; Response.Cookies.Add(cName);

Response.Redirect("cookiereciever.aspx"); //cName.Path = "C:"; } To reciveve the value create

Cookiereciever.aspx

Design: just take one label to show the cookie value Cookiereciever.aspx.cs Write the code in page_load event protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["Name"] != null) Label1.Text = Request.Cookies["Name"].Value; else{ Label1.Text = "there is no cookie"; } } EG: // Store the user's fullname in a cookie for personalization purposes Response.Cookies["funstore_FirstName"].Value = Server.HtmlEncode(txtfname.Text);

Querystring Example:Create querysender.aspx Design:

Code: querysender.aspx.cs

protected void Page_Load(object sender, EventArgs e) { lstItems.Items.Add("A"); lstItems.Items.Add("B"); }

protected void btnshow_Click(object sender, EventArgs e) { if (lstItems.SelectedIndex == -1) { lblError.Text = "You must select an item."; } else { string url = "QueryStringRecipient.aspx?"; url += "Item=" + lstItems.SelectedItem.Text + "&"; url += "Mode=" + chkDetails.Checked.ToString(); Response.Redirect(url); }

QueryStringRecipient.aspx DesignJust take only one label with Id=labelinfo

QueryStringRecipient.aspx.cs file code:Wirte this code in page load event protected void Page_Load(object sender, EventArgs e) { lblInfo.Text = "Item: " + Request.QueryString["Item"]; lblInfo.Text += "
Show Full Record: "; lblInfo.Text += Request.QueryString["Mode"]; }

SQL Connection Database:

protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=vijay;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Insert into tbl_login(uname,pwd)values(@uname,@pwd)", con); cmd.Parameters.Add(new SqlParameter("@uname", SqlDbType.VarChar, 20));

cmd.Parameters["@uname"].Value = tb_user.Text; cmd.Parameters.Add(new SqlParameter("@pwd", SqlDbType.VarChar, 20)); cmd.Parameters["@pwd"].Value = tb_pwd.Text; con.Open(); cmd.ExecuteNonQuery(); Label1.Text = "username password inserted "; con.Close(); }Note 1:Instead of creating connection each time we can create one method or function and call the required object through out the application. Eg: Below page load event, private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here }

SqlConnection con; public void constring() //this is my method {con=new SqlConnection("Data Source=.;Initial Catalog=vijay;Integrated Security=True");

Note 2: //SqlCommand cmd = new SqlCommand("Insert into tbl_login(uname,pwd)values(@uname,@pwd)", con); Instead of this we can write like this By keping the command string in string variable Eg: String insertquery= Insert into tbl_login(uname,pwd)values(@uname,@pwd); SqlCommand cmd = new SqlCommand(insertquery, con); . Exception handling: try { cmd.ExecuteNonQuery(); } catch (SqlException ex) { if (con.State == ConnectionState.Open) { con.Close(); } } __________________________________________________________________________________

con.Open(); }

GRIDVIEW WITH ALL INSERT,UPDATE,DELETE

runat="server" />

CS file code: Rowcommand event protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Insert") { string strCity = ((TextBox)GridView1.FooterRow.FindControl("txt_city")).Text; string strType = ((TextBox)GridView1.FooterRow.FindControl("txt_type")).Text; SqlDataSource1.InsertParameters["City"].DefaultValue = strCity; SqlDataSource1.InsertParameters["Type"].DefaultValue = strType; SqlDataSource1.Insert(); } } __________________________________________________________________________________

Validations for all controls using Javascript:function isEmpty(fieldName1) { var fieldName=fieldName1.name; var fieldValue=fieldName1.value; var len=fieldValue.len; if(fieldValue=="")

{ alert("please enter the required information"); fieldName1.focus(); fieldName1.select(); exit(0); } } /*function dr_deselect(fieldName1) { var fieldName=fieldName1.name; var fieldName=fieldName1.value; }*/ function validateZip(fieldName1) { var fieldName=fieldName1; var str=fieldName.value; var len=str.length; var flag=0; if(str=="") { alert("please enter zip code"); fieldName.focus(); fieldName.select(); } else { if((len2))//checking whether the first char is @ or '.' and number of occurences of @ and '.' { alert("more than one @ or . is not allowed"); fieldName.focus(); fieldName.select(); exit(0); } var lencnt=0; for(i=0;i