473,569 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2358
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...@DONTLI KESPAMwp.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.visibl e = 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.visibl e=true. The
client side event fires and changes a DIV to visibility="blo ck", 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_C lick" />
</asp:Panel>
<asp:Panel runat="server" ID="panelB" Visible="false" >
<asp:DataList runat="server" ID="hugeList">
<ItemTemplate >
some data
<%# Container.ItemI ndex %>
</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(obje ct sender, EventArgs e)
{

panelB.Visible = true;
panelA.Style["display"] = "none";

// prevent button from perfoming postback
Button button = (Button)sender;
button.OnClient Click = "SwitchPanel(1) ; return false;";

hugeList.DataSo urce = new int[10];
hugeList.DataBi nd();
}
</script>

<script type="text/javascript">
//<!--
function SwitchPanel(arg )
{
var panelA = document.getEle mentById('<%=pa nelA.ClientID %>');
var panelB = document.getEle mentById('<%=pa nelB.ClientID %>');

if (arg == 0)
{
panelA.style.di splay = 'block';
panelB.style.di splay = 'none'
}
else
{
panelA.style.di splay = 'none';
panelB.style.di splay = 'block'
}
}
//-->
</script>

-- end snippet --

--
Milosz
"erdos" wrote:
On Feb 24, 9:57 am, Milosz Skalecki [MCAD] <mily...@DONTLI KESPAMwp.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.visibl e = 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.visibl e=true. The
client side event fires and changes a DIV to visibility="blo ck", 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= "SwitchPane l(); 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
2002
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 script and it *seems* to work. In IE it reports "bubbling" and in Firefox "not bubbling" but I really have no direct way to confirm the Firefox results...
13
7460
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 it, a frontend and a backend. Case 1: If vba code on the frontend updates many rows (360,000) on the backend, a form's timer event (from the...
3
4887
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 with enough to fill the space visible without scrolling. Having set the min and max values of my separate vertical scrollbar I use that to scroll the...
1
1570
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 goes on and does some work based on this event. My problem is that once I fire that event, the thread that fired it waits until the thread that...
3
2717
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). 'Do something in code frm.ShowDialog (The Form Load Event fires again)
6
19266
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 PercentEventHandler(object sender, JobCompletedEventArgs e); public event PercentEventHandler PercentCompleted; And fires it:
1
1447
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 of the method, the class is suppose to fire events such as ProgressChanged. And it raises Completed and Failed event on completion and error
5
1372
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 either of these sets fails (no checkbox checked, for example), then an error message control is set and no further processing is done and the page...
2
2715
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 base component does NOT have a Load event as far as i can ascertain. What I need is to have a self-check function called when the component loads....
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.