protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
divStatus.Visible = true;
Page.ClientScript.RegisterStartupScript(this.GetType(), "somekey", "function autoHide(){ setTimeout(function() {document.getlementById('" + divStatus.ClientID + "').style.display='none';},5000);};", true);
}
<form id="form1" runat="server">
<div>
<div class="success" id="divStatus" runat="server" visible="false" >sssssssssssssssss</div>
</div>
</form>
what exactly do i need to add in order to fadeout by itself after few seconds? currently i am displaying div but the user have to click explcitly to close the div and is there a way to close the div by itself using asp.net?
yes i know it does work with fadein and fadeout if you provide the timer but it does not work with asp.net code behind.
//html:
<div class="success" id="divStatus" runat="server" visible="false" ></div>
//code behind:
protected void lnkbtn_add_Click(object sender, EventArgs e)
{
........//more code for deleting
if (deleted)
{
divStatus.visible = true;
}
}
}
There’s no difference. ASP.NET controls render as regular html controls. My hunch is that you are not using the proper client ID that’s rendered. You have two choices:
Add ClientIDMode=”static” in your markup as so:
And then add the javascript function to automatically hide the div:
simply use
<%=divStatus.ClientID%>to get the client id that’sultimately rendered on the page as so:
From codebehind, you can simply call:
UPDATE
If you want to even define the
autoHidefunction in code behind, do as follows (note that the last parameter istruein this case, as opposed tofalseon the previous example):