473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to make event fire once?

I have an asp.net 2.0 button with server and client side click
events. On the first click, both events will fire. On the next
click, only the client side event fires. How do I make the server
side event not fire after the first click?

Thanks,
Brett

Feb 24 '07 #1
6 2347
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...
--
Milosz
"erdos" wrote:
I have an asp.net 2.0 button with server and client side click
events. On the first click, both events will fire. On the next
click, only the client side event fires. How do I make the server
side event not fire after the first click?

Thanks,
Brett

Feb 24 '07 #2
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.

Feb 24 '07 #3
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.

Feb 24 '07 #4
Thanks Milosz. This is close to what I'm doing now but I still don't
see how your code prevents postbacks. Initially, your button has a
server side click_event wired up. Then you give it a onClientClick.
But the server side click_event is still there. This is what I have
now but both always fire.

If a client click_event is present, is that supposed to prevent a
server side client_event from firing? If so, it isn't working for me.

Feb 24 '07 #5
Howdy,

have you run it? i tested it and it's working as you wanted :) i prevent
postback by adding
OnClientClick= "SwitchPanel(); return false;"
"return false;" causes any other javascript code attached to onclick
javascript event won't be executed.
--
Milosz
"erdos" wrote:
Thanks Milosz. This is close to what I'm doing now but I still don't
see how your code prevents postbacks. Initially, your button has a
server side click_event wired up. Then you give it a onClientClick.
But the server side click_event is still there. This is what I have
now but both always fire.

If a client click_event is present, is that supposed to prevent a
server side client_event from firing? If so, it isn't working for me.

Feb 24 '07 #6
Ah! "return false" was the key. I missed that. Thanks.
Feb 24 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mark Szlazak | last post by:
Apparently there is a textarea onscroll event bubbling bug in Firefox and Mozilla: https://bugzilla.mozilla.org/show_bug.cgi?id=229089 I'm trying to check for this bug with the following...
13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
3
by: Peter Row | last post by:
Hi, I have created a user control consisting of a textbox and a separate vertical scroll bar. The textbox is filled with data. However there could be lots of data so I only fill the textbox...
1
by: Michael McCarthy | last post by:
I've written an event that tells me that I've connected properly to a remote telnet location. When I know that I'm connected I fire the event which is being listened for in a bit of code that then...
3
by: Dennis | last post by:
I have the following code for showing a form: dim frm as new myForm frm.ShowDialog (The Form Load Event is fired then I hide the form using Me.Hide when the X in the UR corner is clicked). ...
6
by: sjoshi | last post by:
I have a derived class OraBackup which has a method that calls stored procedure on Oracledb to get status of backup job. Now the base class publishes an event like this: public delegate void...
1
by: Ajak | last post by:
Hi all, I would like to write a class (Task) with a method to do some lengthy process based on several of the class properties. The method is running on different thread. During the execution...
5
by: Shelly | last post by:
Here is the situation. I have a button and I have the click event. When it is clicked, it enters that subroutine (submit_Click). As part of the processing it checks two sets of fields. If...
2
by: ZBINContact | last post by:
I am creating a self-checking set of usercontrols. They tend to call their self-checking functionally in the "Load" event. I have run into a problem with my TextBox usercontrol, however, as the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.