Examples with TextBox & Button& Lable Controls:



  • Create a New WebPage
  • Goto ToolBox
  • DoubleClick on TextBox
  • This will create TextBox1
  • Select TextBox1
  • Goto Properties Window
  • Change the ID to txtSample (Name in C#.Net (ID) in Asp.Net) 
  • Goto ToolBox
  • DoubleClick on Button
  • This will create Button1
  • Select Button1
  • Goto Properties Window
  • Change the Text Property to Red,Change ID to btnRed
  • Similarly for Reamining TwoButtons. 

Design:-




Select the Button btnRed ---- Go to properties window---- Click on Events  Button---- Go to click Event, double click on it ---- write the following code
 
protected void btnRed_Click(object sender, EventArgs e)
{    
        txtSample.BackColor = System.Drawing.Color.Red;
}


Select the Button btnGreen ---- Go to properties window ----Click on Events Button, double click on click Event ---- Write the following code

protected void btnGreen_Click(object sender, EventArgs e)
{
        txtSample.BackColor = System.Drawing.Color.Green;
}


Select the Button btnBlue----Go to properties window ---- Click on Event Button, double click on click Event ---- Write the following code

protected void btnBlue_Click(object sender, EventArgs e)
{
        txtSample.BackColor = System.Drawing.Color.Blue;
}


  Run the Webpage & Check



Example to Perform Addition,Subtraction,Multiplication,Division of Two Numbers.

Create a NewPage,Design the WebPage  like



Generate the Button Click Events of btnAdd,btnSubtract,btnMultiply,btnSubtract
Write the Following code

public partial class ASMDExample : System.Web.UI.Page
{
    int A, B, C;
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        A = Convert.ToInt32(txtNum1.Text);
        B = Convert.ToInt32(txtNum2.Text);
        C = A + B;
        txtResult.Text = C.ToString();
    }
    protected void btnSubtract_Click(object sender, EventArgs e)
    {
        A = Convert.ToInt32(txtNum1.Text);
        B = Convert.ToInt32(txtNum2.Text);
        C = A - B;
        txtResult.Text = C.ToString();
    }
    protected void btnMultiply_Click(object sender, EventArgs e)
    {
        A = Convert.ToInt32(txtNum1.Text);
        B = Convert.ToInt32(txtNum2.Text);
        C = A * B;
        txtResult.Text = C.ToString();
    }
    protected void btnDivide_Click(object sender, EventArgs e)
    {
        A = Convert.ToInt32(txtNum1.Text);
        B = Convert.ToInt32(txtNum2.Text);
        C = A / B;
        txtResult.Text = C.ToString();
    }
}



 Run the WebPage & Check

No comments:

Post a Comment