Loading ...

ASP.NET : How to open an alert box from user control? | CodeAsp.Net

ASP.NET : How to open an alert box from user control?

 /5
0 (0votes)

Today someone asked on forums that how to open a alert box from user control.So I am writing a blog on it.

There is a user control and an aspx.page. In user control, I have one button and in user control's code behind file alert box code. 

User Control Code -

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="testQuestionUC.ascx.cs" Inherits="WebProjects.UserControl.testQuestionUC" %>
<asp:Button ID="btn" runat="server" Text="Click" onclick="btn_Click"  />

using System;

namespace WebProjects.UserControl
{
    public partial class testQuestionUC : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_Click(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "TestAlert", "alert(\'Welcome.\');", true);

        }
    }
}


ASPX Page

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestQuestion.aspx.cs" Inherits="WebProjects.TestQuestion" %>

<%@ Register Src="~/UserControl/testQuestionUC.ascx" TagName="test" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc1:test ID="sidebar1" runat="server" />
    </div>
    </form>
</body>
</html>

Do let me know your feedback or comment.

Ref - http://www.codeasp.net/blogs/raghav_khunger/microsoft-net/790/asp-net-how-to-open-alert-box-from-codebehind-or-server-side

 

Comments (no comments yet)

Top Posts