In asp.net one of the main control is command Button. My scenario is display the confirmation before the event fire. Let we see
It’s simple
Use JavaScript function “confirm”.
Syntax:
[controls]. Attributes.Add(strkeys as string , values as string)
Code :
btnExit.Attributes.Add("OnClick","return confirm('Exit from this Page')");
btnExit – Command Button
Attributes- basic control Attributes( HTML controls or Client controls)
So when you add an Attributes its fire on the Client side without server requst
OnClick- Event Name . Not only the events css also
Confirm- JavaAcript
Example or Events:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// set the Attributes at the time of form loading
btnExit.Attributes..Add("OnClick","return confirm('Exit from this Page')");
}
}
Another one Example with CSS :
protected void grdRackingmaster_RowDataBound(object sender, GridViewRowEventArgs e)
{
// set the row background color of the gridview at the time of DataBound event
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmousemove", "this.style.backgroundColor='#D1D9E5'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
}
}
- when the mouse moves on the gridview control row color changed
Result :
----
No comments:
Post a Comment