We want to open new window and write content on it which we want to write into it.
$("#adv").click(function () {
var html = $("#dvcontent").html();
var w = window.open();
w.document.writeln(html);
});
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["CheckRefresh"] =
Server.UrlDecode(System.DateTime.Now.ToString());
}
}
protected void imgbtn_Click(object sender, ImageClickEventArgs e)
{
//Label2.Text = imgbtn.ToolTip;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
{
Label1.Text = "Hello";
Session["CheckRefresh"] =
Server.UrlDecode(System.DateTime.Now.ToString());
}
else
{
Label1.Text = "Page Refreshed";
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
ViewState["CheckRefresh"] = Session["CheckRefresh"];
}
}
|
PreRender
event and ViewState
variable helps to differentate between the Button click event call or the Refresh page event call. For example, We have a web page having button to display text entered in text box to the Label.PreRender
event is being called, where that session is assigned to the viewstate variable.PreRender
event gets called where that newly assigned session value is assigned to viewstate variable.Viewstate
variable's workflow easily.protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) // If page loads for first time
{
// Assign the Session["update"] with unique value
Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
//=============== Page load code =========================
//============== End of Page load code ===================
}
}
protected void btnDisplay_Click(object sender, EventArgs e)
{
// If page not Refreshed
if (Session["update"].ToString() == ViewState["update"].ToString())
{
//=============== On click event code =========================
lblDisplayAddedName.Text = txtName.Text;
//=============== End of On click event code ==================
// After the event/ method, again update the session
Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
}
else // If Page Refreshed
{
// Do nothing
}
}
protected override void OnPreRender(EventArgs e)
{
ViewState["update"] = Session["update"];
}