locked
avoid page refresh on linkbutton click RRS feed

  • Question

  • User736276958 posted

    hi all

    i am using a link button in first.aspx page

    dialog box is opening on link button click but first.aspx page is refresing 

    how to avoid first.aspx page refresh on linkbutton click

    my code is

    <asp:ScriptManager ID="ScriptManager1" runat="server" ></asp:ScriptManager>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
    <ContentTemplate>
    <table class="table table-striped table-hover">
    <tr>
    <td>
    <asp:Label ID="Label3" runat="server" Text="Industrial Area Name"></asp:Label>
    </td>
    <td>
    <asp:dropdownlist ID="ddlindusarea" runat="server" class="form-control" AutoPostBack="True" OnSelectedIndexChanged="ddlindusarea_SelectedIndexChanged" >
    <asp:ListItem>Select</asp:ListItem>
    </asp:dropdownlist>
    </td>


    <td>
    <asp:LinkButton ID="ibtndetails" class="mdi-action-description" Width="25%" Height="25%" OnClick="ibtndetails_Click" runat="server"/>
    </td>
    </tr>
    </table>
    </ContentTemplate>
    <Triggers>
    <asp:PostBackTrigger ControlID="ibtndetails" />
    </Triggers>
    </asp:UpdatePanel>

    Wednesday, December 16, 2015 10:53 AM

Answers

  • User-369506445 posted

    hi again

    please try below code :

    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>jQuery UI Dialog - Default functionality</title>
        <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
        <script src="//code.jquery.com/jquery-1.10.2.js"></script>
        <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    
        <script>
            function showDialog() {
                $("#dialog").load("default.aspx").dialog({
                    width: 400,
                    height: 400
                });
                return false;
            }
        </script>
    </head>
    <body>
    
        <div id="dialog" title="Basic dialog"></div>
    
        <form runat="server">
            
            <asp:ScriptManager runat="server"></asp:ScriptManager>
            <div id="div1">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <ul>
                            <li>
                                <asp:LinkButton ID="ibtndetails" runat="server" OnClientClick="return  showDialog()">Never clicked</asp:LinkButton></li>
                        </ul>
                        <asp:Label ID="Label1" runat="server" Text="Label" Visible="false"></asp:Label>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="ibtndetails" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
            </div>
        </form>
    </body>
    </html>
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 19, 2015 6:52 AM

All replies

  • User-369506445 posted

    hi

    please change

     <Triggers>
                <asp:PostBackTrigger ControlID="ibtndetails" />
            </Triggers>

    to

        <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ibtndetails" EventName="Click" />
            </Triggers>

    Wednesday, December 16, 2015 11:04 AM
  • User177399542 posted

    Replace this

    <asp:PostBackTrigger ControlID="ibtndetails" />

    with this

     <asp:AsyncPostBackTrigger ControlID="ibtndetails" EventName="Click" />



    Wednesday, December 16, 2015 11:06 AM
  • User736276958 posted

    thanks for your reply

    i have tried your code, it is not working

    link button is firing(i have checked by putting break ponit) but dialog box is not opening

    Wednesday, December 16, 2015 11:10 AM
  • User-369506445 posted

    here i put a simple sample

    first try it and if it was correct , then change to your solution

    <form id="form1" runat="server">
            <asp:ScriptManager runat="server"></asp:ScriptManager>
            <div id="div1">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <ul>
                            <li>
                                <asp:LinkButton ID="ibtndetails" runat="server" OnClick="ibtndetails_Click">Never clicked</asp:LinkButton></li>
                        </ul>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="ibtndetails" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
            </div>
        </form>

    Wednesday, December 16, 2015 11:23 AM
  • User736276958 posted

    i have used your code ans also i have added on label

    on linkbutton click the label has to be displayed

    but label is not diaplaying

    my code is

    <asp:ScriptManager runat="server"></asp:ScriptManager>
    <div id="div1">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <ul>
    <li>
    <asp:LinkButton ID="ibtndetails" runat="server" OnClick="ibtndetails_Click">Never clicked</asp:LinkButton></li>
    </ul>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="ibtndetails" EventName="Click" />
    </Triggers>
    </asp:UpdatePanel>
    </div>
    <asp:Label ID="Label1" runat="server" Text="Label" Visible="false"></asp:Label>

    aspx.cs page

    protected void ibtndetails_Click(object sender, EventArgs e)
    {
    Label1.Visible = true;
    Label1.Text = "page is refreshing";
    }

    page is not refreshing but label is not displaying

    Wednesday, December 16, 2015 11:42 AM
  • User-369506445 posted

    because you must put your controls into Content-template, please try below code :

     <asp:ScriptManager runat="server"></asp:ScriptManager>
            <div id="div1">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <ul>
                            <li>
                                <asp:LinkButton ID="ibtndetails" runat="server" OnClick="ibtndetails_Click">Never clicked</asp:LinkButton>
                            </li>
                        </ul>
                        <asp:Label ID="Label1" runat="server" Text="Label" Visible="false"></asp:Label>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="ibtndetails" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
            </div>

    Wednesday, December 16, 2015 11:53 AM
  • User736276958 posted

    Thanq its working

    if i want to display another aspx page as a popup on linkbutton click, then how i have to mention that

    my code is

    <script type="text/javascript">
    function ibtndetails_Click() {
    showdetails();

    return false;
    }
    </script>

    <asp:ScriptManager runat="server"></asp:ScriptManager>
    <div id="div1">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <ul>
    <li>
    <asp:LinkButton ID="ibtndetails" runat="server" OnClientClick="ibtndetails_Click()">Never clicked</asp:LinkButton></li>
    </ul>
    <asp:Label ID="Label1" runat="server" Text="Label" Visible="false"></asp:Label>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="ibtndetails" EventName="Click" />
    </Triggers>
    </asp:UpdatePanel>
    </div>
    and in external js file showdetails() function is there

    in that i have specified aspx page, which should open in a iframe

    page is not refreshing , also popup is not opening

    Thursday, December 17, 2015 5:38 AM
  • User61956409 posted

    Hi rishe28,

    It seems that you’d like to open target page in dialog in current page without refreshing page when you click linkbutton, if that is the case, you could refer to the following sample.

    <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return showdetails();">LinkButton</asp:LinkButton>
    <br />
    <div id="DivContent">
    </div>
    
    function showdetails() {
        $("#DivContent").load("TargetPage.aspx #content1").dialog();
    
        return false;
    }
    

    TargetPage.aspx

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div id="content1">
                Hello
            </div>
        </form>
    </body>
    </html>
    

    Best Regards,

    Fei Han



    Friday, December 18, 2015 9:49 AM
  • User-369506445 posted

    hi again

    please try below code :

    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>jQuery UI Dialog - Default functionality</title>
        <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
        <script src="//code.jquery.com/jquery-1.10.2.js"></script>
        <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    
        <script>
            function showDialog() {
                $("#dialog").load("default.aspx").dialog({
                    width: 400,
                    height: 400
                });
                return false;
            }
        </script>
    </head>
    <body>
    
        <div id="dialog" title="Basic dialog"></div>
    
        <form runat="server">
            
            <asp:ScriptManager runat="server"></asp:ScriptManager>
            <div id="div1">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <ul>
                            <li>
                                <asp:LinkButton ID="ibtndetails" runat="server" OnClientClick="return  showDialog()">Never clicked</asp:LinkButton></li>
                        </ul>
                        <asp:Label ID="Label1" runat="server" Text="Label" Visible="false"></asp:Label>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="ibtndetails" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
            </div>
        </form>
    </body>
    </html>
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 19, 2015 6:52 AM