Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

No postback on button click

Posted on 2013-02-04
6
Medium Priority
?
4,262 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

705 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