Pages

Subscribe:

Ads 468x60px

Monday, October 15, 2012

How to Go back from current webpage in asp.net suing c#

In this web Programming tutorial we will learn that how we can go back from Current web page to previous one by clicking on the HTML button.
 

How to print a web page using javascript.

In this web Programming tutorial we will learn that how we can add Printing functionality on our web page using javascript in a asp.net or simple html page. see the below code and just copy and paste it.
 
Code to use in HTML part you want to print.
  
// Content Will goes here you want to print.

how to reboot or Restart your computer from web page in asp.net using c#

In this web-healer.blogspot.com's web programming tutorial we will learn that how we can Restart our computer by clicking on a button from our website. So below is the dream code just copy and paste it. and use it in your button's onClick event.
 System.Diagnostics.Process.Start("shutdown.exe", "-r -t 0");

how to shutdown you computer from website in asp.net using c#

In this web-healer.blogspot.com's web programming tutorial we will learn that how we can shutdown our computer by clicking on a button from our website. So below is the dream code just copy and paste it. and use it in your button's onClick event.
System.Diagnostics.Process.Start("shutdown.exe", "-s -t 0")

how to sow date and time on a asp.net page using c#

In this web-healer.blogspot.com's web programming tutorial we will learn that how we can show simple date and time on our web page in asp.net using c#. just copy and paste the below code.
 if (!Page.IsPostBack)
        {
            lbl_date.Text = DateTime.Now.ToLongDateString();
            TxtDateTo.Text = DateTime.Today.ToString("MM/dd/yyyy");
        }  

how to call a javascript function from server side page load event in asp.net using c#

In this web programming tutorial we will learn that how we can call a javascript function from server side in asp.net using c#. see the below simple code in which we are trying to call a radiobutton click event that is defined in Client side, but we will call it on page load event in asp.net using c#. Javascript Function in head section
 
Code for Function call in .CS file on Server side in page load event.
   protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {    
         RBAllHis.Attributes.Add("onclick", "others()");
        }
    }       
 

Saturday, October 13, 2012

import to excel in asp.net using c#

In this web programming tutorial we will learn that how we can import our Gridview data into excel file by click on a link button from our webpage in asp.net using c#.
  protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.ClearContent();
        Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");        
        Response.ContentType = "application/excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);     
        this.ClearControls(GridView1);
        GridView1.RenderControl(htw);       
        Response.Write(sw.ToString());
        Response.End();
    }
  private void ClearControls(Control ctrl)
    {
        for (int i = ctrl.Controls.Count - 1; i >= 0; i--)
        {
            ClearControls(ctrl.Controls[i]);
        }

        if (!(ctrl is TableCell))
        {
            if (ctrl.GetType().GetProperty("SelectedItem") != null)
            {
                LiteralControl literal = new LiteralControl();
                ctrl.Parent.Controls.Add(literal);
                try
                {
                    literal.Text = (string)ctrl.GetType().GetProperty("SelectedItem").GetValue(ctrl, null);
                }
                catch
                {

                }

                ctrl.Parent.Controls.Remove(ctrl);
            }

            else

                if (ctrl.GetType().GetProperty("Text") != null)
                {
                    if (ctrl.Visible == true)
                    {
                        LiteralControl literal = new LiteralControl();
                        ctrl.Parent.Controls.Add(literal);
                        literal.Text = (string)ctrl.GetType().GetProperty("Text").GetValue(ctrl, null);
                        ctrl.Parent.Controls.Remove(ctrl);
                    }
                }
        }
        return;

    }

how to clear all gridview elements in aps.net using c#

In this simple web Programming tutorial we will learn that how we can clear all Controls available in a gridview by just one click instead clearing one by one. like as we clear a form's text fields or other form elements. just copy the below code in your .CS file. Function call.
        this.ClearControls(GridView1);
        GridView1.RenderControl(htw);
Method to clear Gridview fields.
 private void ClearControls(Control ctrl)
    {
        for (int i = ctrl.Controls.Count - 1; i >= 0; i--)
        {
            ClearControls(ctrl.Controls[i]);
        }

        if (!(ctrl is TableCell))
        {
            if (ctrl.GetType().GetProperty("SelectedItem") != null)
            {
                LiteralControl literal = new LiteralControl();
                ctrl.Parent.Controls.Add(literal);
                try
                {
                    literal.Text = (string)ctrl.GetType().GetProperty("SelectedItem").GetValue(ctrl, null);
                }
                catch
                {
                }
                ctrl.Parent.Controls.Remove(ctrl);
            }
            else
                if (ctrl.GetType().GetProperty("Text") != null)
                {
                    if (ctrl.Visible == true)
                    {
                        LiteralControl literal = new LiteralControl();
                        ctrl.Parent.Controls.Add(literal);
                        literal.Text = (string)ctrl.GetType().GetProperty("Text").GetValue(ctrl, null);
                        ctrl.Parent.Controls.Remove(ctrl);
                    }
                }
            }
        return;
    }


how to define session as string in asp.net using c#

In this simple web programming tutorial we will learn that how we can define a Session as string in asp.net using C# to assign it to a string veriable. see the written below code and just copy and paste it.

  string data = Session["Data_var"] as string;

How to find the Previous Page Control's value on a current page in asp.net using c#

In this web Programming tutorial we will learn that how we can find or access a control like label, Dropdown, radiobutton, textbox etc from a previous page and its value to use in current page from gridview in asp.net using c#.
See the below code and just copy and paste the code and have fun.
  
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
     if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (!empty)
            {                
                Label lblcharges = e.Row.FindControl("lbl_charges") as Label;  
             }
         }  
   }

Control Function method .CS file of Current page to access the control's Value.

   private Control FindControl(string controlID, ControlCollection controls)
    {
        foreach (Control c in controls)
        {

            if (c.ID == controlID)

                return c;
            if (c.HasControls())
            {
                Control cTmp = this.FindControl(controlID, c.Controls);

                if (cTmp != null)

                    return cTmp;
            }

        }
        return null;
    }

  

Format String into Money Format in asp.net using c#

In this programming Tutorial we will learn that how we can format amount string into money. below is the code just copy and paste and use it.

string charges = "125.35";
lbl_charges_total.Text  = string.Format("{0:###,###,##0.00}", charges);

Friday, October 12, 2012

how to add new row in gridview in asp.net using c#

In this web programming tutorial we will learn how we can add new column in a Gridview when there is no record and we want to show a proper message that there is no data against particular search in asp.net using c#. see the below code and copy and past.
          
              int columncount = GridView1.Rows[0].Cells.Count;
              GridView1.Rows[0].Cells.Clear();
              GridView1.Rows[0].Cells.Add(new TableCell());
              GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
              GridView1.Rows[0].Cells[0].Text = "No Record Found ";
              GridView1.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
              GridView1.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Maroon;