Solved

No postback on button click

Posted on 2013-02-04
6
3,682 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
Comment Utility
0
 
LVL 14

Expert Comment

by:dejaanbu
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

11 Experts available now in Live!

Get 1:1 Help Now