Howdy,
OK, i see. Please find example below
-- begin snippet --
<asp:Panel runat="server" ID="panelA">
i'm the default panel
<asp:Button runat="server" ID="btnA" Text="Switch to Panel B"
OnClick="btnA_Click" />
</asp:Panel>
<asp:Panel runat="server" ID="panelB" Visible="false">
<asp:DataList runat="server" ID="hugeList">
<ItemTemplate>
some data
<%# Container.ItemIndex %>
</ItemTemplate>
</asp:DataList>
<asp:Button runat="server" ID="btnB" Text="Switch to Panel A"
OnClientClick="SwitchPanel(0); return false" />
</asp:Panel>
<script runat="server">
protected void btnA_Click(object sender, EventArgs e)
{
panelB.Visible = true;
panelA.Style["display"] = "none";
// prevent button from perfoming postback
Button button = (Button)sender;
button.OnClientClick = "SwitchPanel(1); return false;";
hugeList.DataSource = new int[10];
hugeList.DataBind();
}
</script>
<script type="text/javascript">
//<!--
function SwitchPanel(arg)
{
var panelA = document.getElementById('<%=panelA.ClientID %>');
var panelB = document.getElementById('<%=panelB.ClientID %>');
if (arg == 0)
{
panelA.style.display = 'block';
panelB.style.display = 'none'
}
else
{
panelA.style.display = 'none';
panelB.style.display = 'block'
}
}
//-->
</script>
-- end snippet --
--
Milosz
"erdos" wrote:
On Feb 24, 9:57 am, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
wrote:
Could you explain a little bit more what you're trying to do? Should it
prevent the postback or just not to fire server side event handler? Paste
some code...
Here's the scenario: ControlA.visible = false loads initially.
ControlA will load much data once the user clicks Button1. So I'm
only loading data on demand. At some point, the user decides they
want to view that data and clicks Button1. This fires Button1_Click()
server side and loads ControlA and sets ControlA.visible=true. The
client side event fires and changes a DIV to visibility="block", which
ControlA sits in. Now ControlA is visible. Next the user clicks
Button2, which hides ControlA client side and displays ControlB. The
user clicks Button1, which client side hides ControlB and displays
ControlA but does not hit the server again, since ControlA is already
loaded with data.
I may have three buttons and each toggles visibility of a control but
only one control displays at a time. I don't need to load data into
the controls after they are initially displayed. That's what I want
to prevent; hitting the server again and again, since there isn't any
need. If I keep hitting the server, I'll just be loading the same
data over and over. It only needs to load on that first click for its
respective button.