Showing posts with label type. Show all posts
Showing posts with label type. Show all posts

Thursday, March 29, 2012

Newbie : Adding an onclick event to server control, prevents postback.??

Hi,

I have a .net page that basically has two buttons on it. Each
button when
rendered by the server basically seem to have a type of "SUBMIT". What
i want is to be able to disable one of the buttons when a user clicks
on it and have the server process the operation and then renable it
went it's done.

I added the following piece of code to my Page_Load event.

MyButton.Attributes.Add("onclick", "this.disabled=true;");

This worked fine except that my event handler in the code-behind,
ExportButton_Click is not fired and so nothign happens except for the
button being disabled. Can someone give me detailed information on how
this can be done as I'm relatively new to C# , Javascript and .Net.

I was reading about the RegisterOnSubmit statement and such but it
did not
seem to work. What am I missing? What is an easy way to accomplish
this?

Code snippets/ links much appreaciated.

Thanksyes this is a problem.
one way around this is to hide the button instead.
if looks a bit stupid but you could have a disabled button which is hidden
until you click and hide the real button.
a bit mickey mouse but what can you do?

if you find a better way, please post it.
a

"Dr Deadpan" <drdeadpan@.yahoo.com> wrote in message
news:a944d23e.0311201528.32794f68@.posting.google.c om...
> Hi,
> I have a .net page that basically has two buttons on it. Each
> button when
> rendered by the server basically seem to have a type of "SUBMIT". What
> i want is to be able to disable one of the buttons when a user clicks
> on it and have the server process the operation and then renable it
> went it's done.
> I added the following piece of code to my Page_Load event.
> MyButton.Attributes.Add("onclick", "this.disabled=true;");
> This worked fine except that my event handler in the code-behind,
> ExportButton_Click is not fired and so nothign happens except for the
> button being disabled. Can someone give me detailed information on how
> this can be done as I'm relatively new to C# , Javascript and .Net.
> I was reading about the RegisterOnSubmit statement and such but it
> did not
> seem to work. What am I missing? What is an easy way to accomplish
> this?
> Code snippets/ links much appreaciated.
> Thanks
Instead of adding an "onClick" attribute to the button,
why not just disable it from the buttons click event?
ie. myButton.Enabled = False

I guess what you are trying to achieve is to prevent the
user from clicking the button more than once.
You should also make sure you have wired up your event
handlers for the button.

eg. protected WithEvents btnMyButton As Button

protected sub btnMyButton_Click() Handles btnMyButton.Click
end sub

This is VB code, but you need to make sure you declare
your button using 'WithEvent', and wire up the proper
event (using the 'Handles' statement) to the method that
will be handling the event.

It might also be a good idea to set the AutoEventWireup
directive in your .aspx page to False, otherwise your
event will fire twice.

Hope this helps

>--Original Message--
>Hi,
> I have a .net page that basically has two buttons on
it. Each
>button when
>rendered by the server basically seem to have a type
of "SUBMIT". What
>i want is to be able to disable one of the buttons when a
user clicks
>on it and have the server process the operation and then
renable it
>went it's done.
> I added the following piece of code to my Page_Load
event.
>MyButton.Attributes.Add("onclick", "this.disabled=true;");
> This worked fine except that my event handler in the
code-behind,
>ExportButton_Click is not fired and so nothign happens
except for the
>button being disabled. Can someone give me detailed
information on how
>this can be done as I'm relatively new to C# , Javascript
and .Net.
> I was reading about the RegisterOnSubmit statement and
such but it
>did not
>seem to work. What am I missing? What is an easy way to
accomplish
>this?
> Code snippets/ links much appreaciated.
>Thanks
>.
"Rory" <anonymous@.discussions.microsoft.com> wrote in message news:<069e01c3aff6$1699ce20$a401280a@.phx.gbl>...
> Instead of adding an "onClick" attribute to the button,
> why not just disable it from the buttons click event?
> ie. myButton.Enabled = False

I cannot do this as it won't work. What the above will do, is disable
the button once it gets bakc to the client. All the while while the
server is actually running the code in the event handler, the button
will remain Enabled and will become disabled once the code behind is
done - definitely not what I wnat. I read a post earlier on about
doing it an easier way somewhere.
Please, all you guru's , keep the comments coming..

DrD

Monday, March 26, 2012

Newbie class inheritance question

I'm running into a simple issue when instatiating a derived class that
calls a custom constructor. Here's the type of code found in the
parent class:

Public Class parent
Private _a As Long
Private _b As Long
Private _c As String
....

Public Sub New(ByVal a As Long, ByVal b As Long, ByRef c As
String)
_a = a
_b = b
_c = c
EndSub
EndClass

And now the derived class:

Public Class child
Inherits parent

' apparently, i have to redeclare the private vars found in the
parent?
Private _a As Long
Private _b As Long
Private _c As String
....
' cannot inherit the constructor, so define identical one here
Public Sub New(ByVal a As Long, ByVal b As Long, ByRef c As
String)
' call mybase.new to assign vars
MyBase.New(a, b, c)
EndSub
EndClass

By calling 'mybase.new' in the child class, I had expected the var
assignments in the parent to be executed, populating the vars declared
in the child.
What I found with the above class definitions is that the child 'var
_c' is NOT assigned a value.

I'm sure there's a simple answer, but I'm a beginner. Also, I found
some MSDN articles on class inheritance in the 'Upgrading to .NET'
section, but am looking for something that goes deeper. Any idea
where I can find articles that go into greater depth on the subject of
class inheritance?

Thanks... JonJon, "Private" means "Private". Not even a child class can see private
members. You would need to declare them as protected in the parent in order
for the child to use them.

And as a general rule, you should avoid having derived classes access fields
in the parent class. Let them stay private, but declare protected properties
to access them:

Protected Property A as Long
Get
Return _a
End Get
Set
_a = Value
End Set
End Property

This way, the parent class is in control of when these fields are set, and
the values to which it may be set. For instance, you can put code in the Set
accessor to validate the value, or even put code in the Get accessor to get
the value from somewhere else. If you allow your child classes to access the
fields directly, then the fields will _always_ have to be there, just the
way they are, or you'll break the derived classes.
--
John Saunders
Internet Engineer
john.saunders@.surfcontrol.com

"Jon" <to_jon@.hotmail.com> wrote in message
news:e4b2505c.0308061218.513521ee@.posting.google.c om...
> I'm running into a simple issue when instatiating a derived class that
> calls a custom constructor. Here's the type of code found in the
> parent class:
> Public Class parent
> Private _a As Long
> Private _b As Long
> Private _c As String
> ...
> Public Sub New(ByVal a As Long, ByVal b As Long, ByRef c As
> String)
> _a = a
> _b = b
> _c = c
> EndSub
> EndClass
> And now the derived class:
> Public Class child
> Inherits parent
> ' apparently, i have to redeclare the private vars found in the
> parent?
> Private _a As Long
> Private _b As Long
> Private _c As String
> ...
> ' cannot inherit the constructor, so define identical one here
> Public Sub New(ByVal a As Long, ByVal b As Long, ByRef c As
> String)
> ' call mybase.new to assign vars
> MyBase.New(a, b, c)
> EndSub
> EndClass
> By calling 'mybase.new' in the child class, I had expected the var
> assignments in the parent to be executed, populating the vars declared
> in the child.
> What I found with the above class definitions is that the child 'var
> _c' is NOT assigned a value.
> I'm sure there's a simple answer, but I'm a beginner. Also, I found
> some MSDN articles on class inheritance in the 'Upgrading to .NET'
> section, but am looking for something that goes deeper. Any idea
> where I can find articles that go into greater depth on the subject of
> class inheritance?
> Thanks... Jon