0% found this document useful (0 votes)
32 views7 pages

Anshika Assignment.

The document discusses code samples for checking empty query strings, programmatically changing label text color and width, enabling/disabling text boxes and changing font size, converting between Celsius and Fahrenheit, and storing objects in session state and SQL server.

Uploaded by

Aditya Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views7 pages

Anshika Assignment.

The document discusses code samples for checking empty query strings, programmatically changing label text color and width, enabling/disabling text boxes and changing font size, converting between Celsius and Fahrenheit, and storing objects in session state and SQL server.

Uploaded by

Aditya Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1. Write a program to check whether empty query string is entered in Asp.net.

= using System;

using System.Web;

public class QueryStringChecker

public static bool IsEmptyQueryString(HttpContext context)

// Get the query string.

string queryString = context.Request.QueryString.ToString();

// Check if the query string is empty.

if (queryString == "")

return true;

else

return false;

2. Write a program to change colour or label text control programmatically in Asp.

= Here is the code to change the color of a label text control programmatically in ASP.NET:

using System;

using System.Web;

public partial class WebForm1 : System.Web.UI.Page


{

protected void Button1_Click(object sender, EventArgs e)

// Get the label control.

Label label = (Label)this.FindControl("Label1");

// Change the label text color to red.

label.ForeColor = Color.Red;

3. Write a program to Enable-Disable Textbox and change width of TextBox programmatically in Asp.net.

= Here is the code to enable-disable textbox and change width of textbox programmatically in ASP.NET:

using System;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class WebForm1 : System.Web.UI.Page

protected void Button1_Click(object sender, EventArgs e)

// Get the textbox control.

TextBox textbox = (TextBox)this.FindControl("TextBox1");

// Enable the textbox.

textbox.Enabled = true;
// Change the textbox width to 100px.

textbox.Width = Unit.Pixel(100);

protected void Button2_Click(object sender, EventArgs e)

// Get the textbox control.

TextBox textbox = (TextBox)this.FindControl("TextBox1");

// Disable the textbox.

textbox.Enabled = false;

// Change the textbox width to 200px.

textbox.Width = Unit.Pixel(200);

4. Write a program to increase and decrease font size programmatically.

= Here is the code to increase and decrease font size programmatically:

using System;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class WebForm1 : System.Web.UI.Page

private int fontSize = 12;


protected void Button1_Click(object sender, EventArgs e)

// Increase the font size by 1pt.

fontSize++;

// Update the textbox font size.

TextBox textbox = (TextBox)this.FindControl("TextBox1");

textbox.Font.Size = fontSize;

protected void Button2_Click(object sender, EventArgs e)

// Decrease the font size by 1pt.

fontSize--;

// Update the textbox font size.

TextBox textbox = (TextBox)this.FindControl("TextBox1");

textbox.Font.Size = fontSize;

5. Write a C# code to perform Celcius to Farenheit Conversion and Fahrenheit to Celcius Conversion.

= Here is the C# code to perform Celsius to Fahrenheit Conversion and Fahrenheit to Celsius
Conversion:

using System;

public class TemperatureConverter

{
public static double CelsiusToFahrenheit(double celsius)

return (celsius * 9 / 5) + 32;

public static double FahrenheitToCelsius(double fahrenheit)

return (fahrenheit - 32) * 5 / 9;

public static void Main(string[] args)

// Celsius to Fahrenheit conversion.

double celsius = 32;

double fahrenheit = CelsiusToFahrenheit(celsius);

Console.WriteLine("Celsius: {0}, Fahrenheit: {1}", celsius, fahrenheit);

// Fahrenheit to Celsius conversion.

fahrenheit = 212;

celsius = FahrenheitToCelsius(fahrenheit);

Console.WriteLine("Fahrenheit: {0}, Celsius: {1}", fahrenheit, celsius);

6. Write a ASP Net program to store objects in session state and strong state in SQL.

= Here is an ASP.NET program to store objects in session state and strong state in SQL:

using System;

using System.Web;

using System.Web.SessionState;
using System.Data.SqlClient;

public partial class WebForm1 : System.Web.UI.Page

private static SqlConnection connection;

protected void Page_Load(object sender, EventArgs e)

// Initialize the SQL connection.

connection = new SqlConnection("Data Source=localhost;Initial Catalog=aspnetdemo;Integrated


Security=True");

// Store an object in session state.

Session["MyObject"] = new MyObject("Hello, world!");

// Store an object in strong state in SQL.

SqlCommand command = new SqlCommand("INSERT INTO MyObjects (Name) VALUES (@Name)",


connection);

command.Parameters.AddWithValue("@Name", "Hello, world!");

command.ExecuteNonQuery();

public class MyObject

public string Name { get; set; }

public MyObject(string name)

this.Name = name;
}

You might also like