Solved

No postback on button click

Posted on 2013-02-04
6
3,721 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is Thread.Sleep? 5 44
Excel file not created as expected 7 46
Error on Add method 1 36
Eagerly loading related objects in entity framework 5 23
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

948 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now