I am showing alert at button click and have tab control at page . Alert appears but tab disappears at alert. I want to show alert so that tab will not disappear at alert. Is there any technique how to handle this thing ?
<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
<asp:TabPanel ID="pael1" HeaderText="IP text" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="panel2" HeaderText="text" runat="server">
<ContentTemplate>
// Button Click Event
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
protected _Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "Message", "alert('Connection Successful!')", true);
}
您可以使用:
ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "alert('"+ ex.Message +"');", true);
First of all, you should be using the following command according to the MSDN website ( http://msdn.microsoft.com/en-us/library/asz8zsxy(v=vs.110).aspx ):
Note: the script should be within <script></script>
.
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "Message", "<script type=text/javascript>alert('Connection Successful!');</script>", true);
The script is added to the top of your page, before the content, so the alert is displayed before your page is rendered. In order to fix this issue, use:
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "Message", "<script type=text/javascript>window.onload = function(){alert('Connection Successful!');}</script>", true);
By doing so, you ensure that only when the page (JavaScript window
object) loads the alert is displayed.
If you are using jquery, you can also use:
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "Message", "<script type=text/javascript>$(window).load(function() {alert('Connection Successful!');});</script>", true);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.