user1512593
user1512593

Reputation: 383

Getting rid of the Refresh on button click

I have a asp:Button that has an onclick function. Is there a way to eliminate the refresh that occurs?

Current HTML containing button.

<div id="user" class="font">
                <div id="userPanel">

            <asp:TextBox ID="txtSearch"  runat="server" Width="400px" align="left"></asp:TextBox>

            <asp:Button  ID="searchbutton" text="enter" runat="server" 
                onclick="searchbutton_Click" />

            <asp:Label ID="test" runat="server"></asp:Label>

            </div>

            <asp:UpdatePanel ID="userinfoupdatepanel" runat="server">
                <ContentTemplate>
                    <div class="topcontent">
                        <ul>...</ul>
                    </div> 
                </ContentTemplate>
            </asp:UpdatePanel> 

The button click then calls a function that fills the UL content

Upvotes: 1

Views: 270

Answers (2)

Guffa
Guffa

Reputation: 700212

You can use OnClientClick to bind a Javascript function to handle the click in the browser. If you return false from that fumction, the postback doesn't happen.

Upvotes: 2

Firoz Ansari
Firoz Ansari

Reputation: 2515

You can also add client events using Attributes collection.

searchbutton.Attributes.Add("onclick", "alert('Test')");
searchbutton.Attributes.Add("onclick", "return fnSomeThing(this);");

Upvotes: 0

Related Questions