1.Add two number and display in a detail page
Label3.Text =(Convert.ToInt32(TextBox2.Text) + Convert.ToInt32(TextBox3.Text)).ToString();
2.Click on a link and navigate to different page
Server.Transfer("Contact.aspx");
Response.Redirect("Contact.aspx");
4.Reusable component concept
Usercontrol
pass data from parent to child
------------------------------
parent
------
Label3.Text =(Convert.ToInt32(TextBox2.Text) + Convert.ToInt32(TextBox3.Text)).ToString();
WebUserControl11.labels = Label3.Text;
child
-----
public dynamic labels
{
get { return Label1.Text; }
set { Label1.Text = value; }
}
pass data from child to parent
------------------------------
child
-----
public delegate void WebUserControl1Delegate(dynamic a);
public event WebUserControl1Delegate s;
protected void Button1_Click(object sender, EventArgs e)
{
s(1);
}
parent
------
protected void Page_Load(object sender, EventArgs e)
{
WebUserControl11.s += new WebUserControl1.WebUserControl1Delegate(a);
}
void a(dynamic a)
{
// 1 will get passed
}
3.State mangement
-cookie
-session
-localstorage
-sessionstorage
-query string
Label1
WebUserControl11.Label1
-------
cookie
-------
Set
HttpContext.Response.Cookies.Append("user_id", "1");
Get
var userId = HttpContext.Request.Cookies["user_id"];
In order to add expiry time
---------------------------
using Microsoft.AspNetCore.Http;
CookieOptions cookieOptions = new CookieOptions();
HttpContext.Response.Cookies.Append("first_request", DateTime.Now.ToString(), cookieOptions);
-------
session
-------
var products=Db.GetProducts();
Session["products"]=products //set
var products=Session["products"] as List<Product>; //get
Session["products"]=null; /clear
------------
localstorage
------------
In order to access in cs code
-----------------------------
string script = string.Format("sessionStorage.userId= '{0}';", "12345");
ClientScript.RegisterClientScriptBlock(this.GetType(), "key", script, true)
-------------------------------------------------------------------
Query string
------------
/nextpage.aspx?name=Jenna Doe
Response.Redirect(“nextpage.aspx?name=Jenna Doe”);
var name=HttpContext.Request.Query["name"];
Comments
Post a Comment