Solved

No postback on button click

Posted on 2013-02-04
6
4,006 Views
Last Modified: 2013-02-05
Does anyone know how to stop a postback when a button is clicked.

I just want the button to show another panel and not postback to the entire page.



<asp:LinkButton ID="lnkSaveAs" skinid="empty" Text="Save As" runat="server" autopostback="false" visible="false" >
</asp:LinkButton>

This is the code behind:

Protected Sub lnkSaveAs_Click(sender As Object, e As System.EventArgs) Handles lnkSaveAs.Click
        Me.panelsaveas.Visible = True
    End Sub

I am getting a postback to the entire page.  

Thanks in advance for your help.
0
Comment
Question by:sherbug1015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 11

Expert Comment

by:Deepak Lakkad
ID: 38853522
0
 
LVL 14

Expert Comment

by:dejaanbu
ID: 38853803
if u r handling visiblity inside code-behind, then it will postback. to avoid this, u may have to use ajax.

i would recommend using javascript to handle visibility of the panel.(if your aim is only to show/hide the panel)

<asp:LinkButton ID="lnkSaveAs" skinid="empty" Text="Save As" runat="server" autopostback="false" visible="false" OnClientClick="showPanel();" >
</asp:LinkButton>

<script type="text/javascript">
    var pnlId = '#<%= panelsaveas.ClientID %>';

    function ShowPanel(elm) {
//if you have jquery reference , use the following
        if ($(pnlId).is("visible"))
            $(pnlId).hide();
        else
            $(pnlId).show();
   
//if you r not using jquery, use the following js
if(pnlId.style.display == 'none')
 pnlId.style.display = 'block';
else
pnlId.style.display = 'none';
}
</script>

Open in new window

0
 
LVL 10

Expert Comment

by:Monica P
ID: 38853881
If you no need any postback to happen then you can have script to done this

     <script>
function ShowPanel() {

    document.getElementById('<%=Panel1.ClientID %>').style.display = 'block'
    return false;
}
     </script>

Open in new window


<asp:LinkButton ID="LinkButton1" runat="server" [b]OnClientClick ="return ShowPanel();"[/b]>LinkButton</asp:LinkButton>
        <asp:Panel ID="Panel1" runat="server" style="display:none">
        
        <p> Hi Test </p>
        
    </asp:Panel>

Open in new window

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 500 total points
ID: 38853981
Hi,

Seems like you have a Panel called - panelsaveas

So the code is -

<asp:LinkButton ID="lnkSaveAs" skinid="empty" Text="Save As" onClientClick="return ShowPanel();" runat="server">
</asp:LinkButton>
<asp:Panel ID="panelsaveas" runat="server" style="display:none;" >
 Your Panel content
</asp:Panel>

<script type="text/javascript">
function ShowPanel()
{
 document.getElementById('<%=panelsaveas.ClientID%>').style.display="block";
 return false;
}
</script>

Open in new window


Moreover, i also noticed that, you set Visible="False" for LinkButton!

And also in @AkilaPalanimuthu Code, remove the
[b]

Open in new window

and
 [/b]

Open in new window

 from this line -
OnClientClick ="return ShowPanel();"

Open in new window


Hope it helps u...
0
 
LVL 10

Expert Comment

by:Monica P
ID: 38854182
That's with unexpected click on bold icon in the editor..Except that u can use as such

 <script>
function ShowPanel() {

    document.getElementById('<%=Panel1.ClientID %>').style.display = 'block'
    return false;
}
     </script>

Open in new window


<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick ="return ShowPanel();">LinkButton</asp:LinkButton>
        <asp:Panel ID="Panel1" runat="server" style="display:none">
        
        <p> Hi Test </p>
        
    </asp:Panel>

Open in new window

0
 

Author Closing Comment

by:sherbug1015
ID: 38856204
Thank you
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question