locked
button click show you want to login or register RRS feed

  • Question

  • User-807418713 posted

    hello

    In my aspx c# button click

    on user button click i want to show alert "You Like To Register / Login" there it should be two button in alert if user click in that alert login then login.aspx if user click register then register.aspx

    Thanking You

    Tuesday, November 17, 2020 1:35 PM

Answers

  • User-939850651 posted

    Hi Gopi.MCA,

    I created a simple example, but I am not sure if this can achieve the effect you expect.

    <head runat="server">
        <link href="Content/bootstrap.min.css" rel="stylesheet" />
        <title></title>
        <script src="Scripts/jquery-3.5.1.min.js"></script>
        <script src="Scripts/bootstrap.min.js"></script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="container">
                <asp:Button ID="choseBtn2" OnClick="choseBtn_Click" runat="server" Text="ChoseWhatToDo2" CssClass="btn-primary" />
            </div>
        </form>
    </body>
     protected void Page_Init(object sender, EventArgs e)
            {
                Panel p = new Panel();
                p.ID = "testPanel";
                p.Attributes.Add("role", "dialog");
                p.Attributes.Add("tabindex", "-1");
                p.Attributes.Add("aria-hidden", "true");
                p.Style.Add("display", "none");
                p.CssClass = "modal fade";
                Panel p2 = new Panel();
                p2.Attributes.Add("role", "document");
                p2.CssClass = "modal-dialog";
                p.Controls.Add(p2);
                Panel p3 = new Panel();
                p3.CssClass = "modal-content";
                p2.Controls.Add(p3);
    
                //Panel p4 = new Panel();
                //p4.CssClass = "modal-header";
    
                Panel p5 = new Panel();
                p5.CssClass = "modal-body";
                p5.Controls.Add(new Literal
                {
                    ID = "Lit1",
                    Text = "What you want to do?"
                });
                p3.Controls.Add(p5);
                Panel p6 = new Panel();
                p6.CssClass = "modal-footer";
                LinkButton btn1 = new LinkButton();
                btn1.Text = "Register";
                btn1.CssClass = "btn btn-primary";
                btn1.PostBackUrl = "Register.aspx";
                LinkButton btn2 = new LinkButton();
                btn2.Text = "Login";
                btn2.CssClass = "btn btn-primary";
                btn2.PostBackUrl = "Login.aspx";
                p6.Controls.Add(btn1);
                p6.Controls.Add(btn2);
                p3.Controls.Add(p6);
    
                form1.Controls.Add(p);
    
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void choseBtn_Click(object sender, EventArgs e)
            {
                Panel testPanel = form1.FindControl("testPanel") as Panel;
                testPanel.Visible = true;
                testPanel.CssClass = "modal fade show";
                testPanel.Style.Add("display", "block");
                testPanel.Style.Add("background", "rgba(0,0,0, 0.5)");
            }

    Result:




    If you only need to call the function in the script from the button click event, then you can refer to this case:

    https://forums.asp.net/t/2098339.aspx?How+to+create+popups+using+code+behind

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 19, 2020 7:21 AM

All replies

  • User-939850651 posted

    Hi Gopi.MCA,

    According to your description, I recommand you could use Bootstrap Model to achieve your requirement. 

    Here is a simple demo:

    <head runat="server">
        <link href="Content/bootstrap.min.css" rel="stylesheet" />
        <title></title>
        <script src="Scripts/jquery-3.5.1.min.js"></script>
        <script src="Scripts/bootstrap.min.js"></script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="container">
                <asp:Button ID="choseBtn" OnClientClick="return false;" runat="server" Text="ChoseWhatToDo" CssClass="btn-primary" data-toggle="modal" data-target="#exampleModal" />
                <%--<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Chose What To Do</button>--%>
            </div>
            <!-- Modal -->
            <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <%--<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>--%>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            What you want to do?
                        </div>
                        <div class="modal-footer">
                            <%--<button type="button" class="btn btn-primary">Register</button>
                            <button type="button" class="btn btn-primary">Login</button>--%>
                            <asp:LinkButton Text="Register" class="btn btn-primary" runat="server" PostBackUrl="Register.aspx"/>
                            <asp:LinkButton Text="Login" class="btn btn-primary" runat="server" PostBackUrl="Login.aspx"/>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </body>

    Result:

    Best regards,

    Xudong Peng

    Wednesday, November 18, 2020 5:18 AM
  • User-807418713 posted

    Hello

    Can it be done using asp.net C# code behind..?

    Possible? if button click

    Wednesday, November 18, 2020 11:15 AM
  • User-939850651 posted

    Hi Gopi.MCA,

    I created a simple example, but I am not sure if this can achieve the effect you expect.

    <head runat="server">
        <link href="Content/bootstrap.min.css" rel="stylesheet" />
        <title></title>
        <script src="Scripts/jquery-3.5.1.min.js"></script>
        <script src="Scripts/bootstrap.min.js"></script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="container">
                <asp:Button ID="choseBtn2" OnClick="choseBtn_Click" runat="server" Text="ChoseWhatToDo2" CssClass="btn-primary" />
            </div>
        </form>
    </body>
     protected void Page_Init(object sender, EventArgs e)
            {
                Panel p = new Panel();
                p.ID = "testPanel";
                p.Attributes.Add("role", "dialog");
                p.Attributes.Add("tabindex", "-1");
                p.Attributes.Add("aria-hidden", "true");
                p.Style.Add("display", "none");
                p.CssClass = "modal fade";
                Panel p2 = new Panel();
                p2.Attributes.Add("role", "document");
                p2.CssClass = "modal-dialog";
                p.Controls.Add(p2);
                Panel p3 = new Panel();
                p3.CssClass = "modal-content";
                p2.Controls.Add(p3);
    
                //Panel p4 = new Panel();
                //p4.CssClass = "modal-header";
    
                Panel p5 = new Panel();
                p5.CssClass = "modal-body";
                p5.Controls.Add(new Literal
                {
                    ID = "Lit1",
                    Text = "What you want to do?"
                });
                p3.Controls.Add(p5);
                Panel p6 = new Panel();
                p6.CssClass = "modal-footer";
                LinkButton btn1 = new LinkButton();
                btn1.Text = "Register";
                btn1.CssClass = "btn btn-primary";
                btn1.PostBackUrl = "Register.aspx";
                LinkButton btn2 = new LinkButton();
                btn2.Text = "Login";
                btn2.CssClass = "btn btn-primary";
                btn2.PostBackUrl = "Login.aspx";
                p6.Controls.Add(btn1);
                p6.Controls.Add(btn2);
                p3.Controls.Add(p6);
    
                form1.Controls.Add(p);
    
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void choseBtn_Click(object sender, EventArgs e)
            {
                Panel testPanel = form1.FindControl("testPanel") as Panel;
                testPanel.Visible = true;
                testPanel.CssClass = "modal fade show";
                testPanel.Style.Add("display", "block");
                testPanel.Style.Add("background", "rgba(0,0,0, 0.5)");
            }

    Result:




    If you only need to call the function in the script from the button click event, then you can refer to this case:

    https://forums.asp.net/t/2098339.aspx?How+to+create+popups+using+code+behind

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 19, 2020 7:21 AM