sherbug1015
asked on
No postback on button click
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.
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.
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)
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>
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>
<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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>
<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>
ASKER
Thank you
Here are few links which will help you to get your result
http://stackoverflow.com/questions/176827/disable-the-postback-on-an-asplinkbutton
http://stackoverflow.com/questions/4067925/asp-net-link-button-preventing-postback
http://forums.asp.net/t/1275403.aspx/1
- Deepak Lakkad