please help :: button.click event 
Author Message
 please help :: button.click event
Not sure about your first problem, but there are no default properties in
.NET-based languages.

RMD


Quote:
> I'm using a code-behind file and I'm trying to use a Button, the problem
is
> that I can't interact with the OnClick property in code-behind (because
it's
> protected) and when I try to add an EventHandler to the Click event it
> doesn't work.
> I found out that if I try it in an aspx file and not actually create a new
> instance of a Button but instead just use the...
> <asp:Button Id="myButton" ... />
> ...then it will work.
> As soon as I commented out the...
> Button myButton = new Button();
> ...and saved it worked.

> Can someone please tell me how to do this?

> Also, if I have a class called Client, how can I make it so when I create
an
> instance called myClient I can do...
> lblTest.Text = myClient;
> and it returns the Name property of the class? Currently I have to do...
> lblTest.Text = myClient.Name;

> Regards,
> John Rebbeck
> Phone: 0416 199 505





Thu, 01 Jul 2004 16:10:43 GMT  
 please help :: button.click event
Are you using OnClick, which is a client-side event, or OnServerClick?
OnServerClick will let you call functions on the server whereas OnClick
would only be used for client-side scripts and that may be why it's not
enabled.

        Hope this helps,
        Mark Fitzpatrick
        Microsoft MVP - FrontPage


Quote:
> I'm using a code-behind file and I'm trying to use a Button, the problem
is
> that I can't interact with the OnClick property in code-behind (because
it's
> protected) and when I try to add an EventHandler to the Click event it
> doesn't work.
> I found out that if I try it in an aspx file and not actually create a new
> instance of a Button but instead just use the...
> <asp:Button Id="myButton" ... />
> ...then it will work.
> As soon as I commented out the...
> Button myButton = new Button();
> ...and saved it worked.

> Can someone please tell me how to do this?

> Also, if I have a class called Client, how can I make it so when I create
an
> instance called myClient I can do...
> lblTest.Text = myClient;
> and it returns the Name property of the class? Currently I have to do...
> lblTest.Text = myClient.Name;

> Regards,
> John Rebbeck
> Phone: 0416 199 505




Fri, 02 Jul 2004 06:13:04 GMT  
 please help :: button.click event

Quote:
> Also, if I have a class called Client, how can I make it so when I create
an
> instance called myClient I can do...
> lblTest.Text = myClient;
> and it returns the Name property of the class? Currently I have to do...
> lblTest.Text = myClient.Name;

John,

We have already covered this issue in a previous post. You can not do that!
A Class is a data type and so is a string. You have to assign "like" data
types in order of that to work. In other words, you have to use the syntax
"lblTest.Text = myClient.Name". There is no way around this.

One other hint, you may want to reconsider posting to so many different
places. Typically, it is best to only post to one news group but you want to
be especially carfull when posting to groups like
"microsoft.public.dotnet.faqs". You are asking for very specific programming
help and the FAQ group isn't meant to handle those types of questions.

--
Regards,

Cal



Fri, 02 Jul 2004 06:22:42 GMT  
 please help :: button.click event
Well you can't really get the server to click a button (well not that I know
anyway).

John


Quote:
> Are you using OnClick, which is a client-side event, or OnServerClick?
> OnServerClick will let you call functions on the server whereas OnClick
> would only be used for client-side scripts and that may be why it's not
> enabled.

>         Hope this helps,
>         Mark Fitzpatrick
>         Microsoft MVP - FrontPage



> > I'm using a code-behind file and I'm trying to use a Button, the problem
> is
> > that I can't interact with the OnClick property in code-behind (because
> it's
> > protected) and when I try to add an EventHandler to the Click event it
> > doesn't work.
> > I found out that if I try it in an aspx file and not actually create a
new
> > instance of a Button but instead just use the...
> > <asp:Button Id="myButton" ... />
> > ...then it will work.
> > As soon as I commented out the...
> > Button myButton = new Button();
> > ...and saved it worked.

> > Can someone please tell me how to do this?

> > Also, if I have a class called Client, how can I make it so when I
create
> an
> > instance called myClient I can do...
> > lblTest.Text = myClient;
> > and it returns the Name property of the class? Currently I have to do...
> > lblTest.Text = myClient.Name;

> > Regards,
> > John Rebbeck
> > Phone: 0416 199 505




Fri, 02 Jul 2004 06:51:46 GMT  
 please help :: button.click event

Quote:
> > Also, if I have a class called Client, how can I make it so when I
create
> an
> > instance called myClient I can do...
> > lblTest.Text = myClient;
> > and it returns the Name property of the class? Currently I have to do...
> > lblTest.Text = myClient.Name;

> John,

> We have already covered this issue in a previous post. You can not do
that!
> A Class is a data type and so is a string. You have to assign "like" data
> types in order of that to work. In other words, you have to use the syntax
> "lblTest.Text = myClient.Name". There is no way around this.

Actually, you can do this if your language supports default conversions
(JScript) or overloaded operators (C#, C++).

In JScript, you can override the ToString method so that it returns the Name
property; then when you assign the object to something that is of type
String, it will get converted automatically:

// ----------

import System.Windows.Forms
var b = new Button
var p = new Person("Fred")
b.Text = p
print(b.Text)

class Person
{
  private var name : String

  function Person(name)
  {
    this.name = name
  }

  function ToString() : String
  {
    return name
  }

Quote:
}

// ----------

In C#, you can have an implicit operator do the work:

using System;
using System.Windows.Forms;

class Person
{
  string name;

  static void Main()
  {
    Button b = new Button();
    Person p = new Person("Fred");
    b.Text = p;
    Console.WriteLine(b.Text);
  }

  public Person(string name)
  {
    this.name = name;
  }

  public static implicit operator string(Person ob)
  {
    return ob.name;
  }

Quote:
}

// ----------

Peter

--

Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
Please post all questions to the group. Thanks.



Fri, 02 Jul 2004 06:58:49 GMT  
 please help :: button.click event
No, the server doesn't "click" the button, but this is the server-side
attribute you use to add a handler for the server for when the user clicks
the button. If you want to handle the posting (or getting) or data from your
page, you add the OnServerClick attribute to your tag like so:


<html>
...
<script runat="server">
private void MyButton_Click(Object source, EventArgs args) {
    lblSomeLabel.Text = "Hello, world!";

Quote:
}

</script>
...
<asp:Button id="MyButton" runat="server" Text="Say hello!"
OnServerClick="MyButton_Click"/>
...
</html>

--

Heath Stewart
Systems Administrator / Developer
EsotericRealm
http://www.esotericrealm.com

Quote:
> Well you can't really get the server to click a button (well not that I
know
> anyway).

> John



> > Are you using OnClick, which is a client-side event, or OnServerClick?
> > OnServerClick will let you call functions on the server whereas OnClick
> > would only be used for client-side scripts and that may be why it's not
> > enabled.

> >         Hope this helps,
> >         Mark Fitzpatrick
> >         Microsoft MVP - FrontPage



> > > I'm using a code-behind file and I'm trying to use a Button, the
problem
> > is
> > > that I can't interact with the OnClick property in code-behind
(because
> > it's
> > > protected) and when I try to add an EventHandler to the Click event it
> > > doesn't work.
> > > I found out that if I try it in an aspx file and not actually create a
> new
> > > instance of a Button but instead just use the...
> > > <asp:Button Id="myButton" ... />
> > > ...then it will work.
> > > As soon as I commented out the...
> > > Button myButton = new Button();
> > > ...and saved it worked.

> > > Can someone please tell me how to do this?

> > > Also, if I have a class called Client, how can I make it so when I
> create
> > an
> > > instance called myClient I can do...
> > > lblTest.Text = myClient;
> > > and it returns the Name property of the class? Currently I have to
do...
> > > lblTest.Text = myClient.Name;

> > > Regards,
> > > John Rebbeck
> > > Phone: 0416 199 505




Fri, 02 Jul 2004 14:30:57 GMT  
 please help :: button.click event


Quote:


> > <snip>
> > A Class is a data type and so is a string. You have to assign "like" data
> > types in order of that to work. In other words, you have to use the syntax
> > "lblTest.Text = myClient.Name". There is no way around this.

> Actually, you can do this if your language supports default conversions
> (JScript) or overloaded operators (C#, C++).

> In JScript, you can override the ToString method so that it returns the Name
> property; then when you assign the object to something that is of type
> String, it will get converted automatically:

><snip code>

> In C#, you can have an implicit operator do the work:

><snip code>

This is getting rather frustrating. From this and other threads, it now looks
like VB.NET missed out on a number of features VB6 had *and that those
features are available in other .NET languages*!

Non-parameterised default properties;
Semi-automatic object disposal (that is "using" provides the partial
replacement of DF, and it is not provided for VB.NET which is where the
majority of programmers will be looking for such a feature);
What's next?

Quote:
> Peter

> --

> Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
> Please post all questions to the group. Thanks.

Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)


Fri, 02 Jul 2004 16:05:44 GMT  
 please help :: button.click event
Can anyone help with John's first problem? I have written a similar post
entitled "Programatically Creating WebControls and Wiring Up Evetns" that is
basically the same question as John's. Has anyone managed to do this yet?

Gary Brewer

PS: John, I admire the way your post is 2 days a head of everyone else :)


Quote:
> I'm using a code-behind file and I'm trying to use a Button, the problem
is
> that I can't interact with the OnClick property in code-behind (because
it's
> protected) and when I try to add an EventHandler to the Click event it
> doesn't work.
> I found out that if I try it in an aspx file and not actually create a new
> instance of a Button but instead just use the...
> <asp:Button Id="myButton" ... />
> ...then it will work.
> As soon as I commented out the...
> Button myButton = new Button();
> ...and saved it worked.

> Can someone please tell me how to do this?

> Also, if I have a class called Client, how can I make it so when I create
an
> instance called myClient I can do...
> lblTest.Text = myClient;
> and it returns the Name property of the class? Currently I have to do...
> lblTest.Text = myClient.Name;

> Regards,
> John Rebbeck
> Phone: 0416 199 505




Fri, 02 Jul 2004 19:21:50 GMT  
 please help :: button.click event
Peter,

Quote:
> Actually, you can do this if your language supports default conversions
> (JScript) or overloaded operators (C#, C++).

As I do not work a lot with C# (yet ;-), I was under the impression that the
only operators that it could overload were the normal everyday operators as
defined here:

ms-help://MS.VSCC/MS.MSDNVS/csref/html/vclrfoverloadableoperators.htm

After further snooping I did run across the docs that covered what you are
talking about with implicit and explicit overloading of types:

ms-help://MS.VSCC/MS.MSDNVS/csref/html/vclrfOperator.htm

My mistake. I am not sure if clearer docs would have helped in this scenario
or not but I am sorry for any confusion I may have caused. :(

Quote:
> In JScript, you can override the ToString method so that it returns the
Name
> property; then when you assign the object to something that is of type
> String, it will get converted automatically:

Hmmm, the JScript example you showed dealt with the "ToString", as I am not
familiar with JScript, how would that work for an "int" type (or any other
type for that matter). Is the auto conversion only applicable to strings?

Thanks for you insight!

Regards,

Cal



Fri, 02 Jul 2004 21:22:51 GMT  
 please help :: button.click event

message

Quote:
> Hmmm, the JScript example you showed dealt with the "ToString", as I am not
> familiar with JScript, how would that work for an "int" type (or any other
> type for that matter). Is the auto conversion only applicable to strings?

> Thanks for you insight!

System.Object has a ToString method. Everything in the dotNet world
has System.Object as an implicit base class.

mule
--
"jewels and binoculars hang from the head of the mule"
                                             Bob Dylan



Sat, 03 Jul 2004 01:14:21 GMT  
 please help :: button.click event

Quote:
> > Hmmm, the JScript example you showed dealt with the "ToString", as I am
not
> > familiar with JScript, how would that work for an "int" type (or any
other
> > type for that matter). Is the auto conversion only applicable to
strings?

> > Thanks for you insight!

> System.Object has a ToString method. Everything in the dotNet world
> has System.Object as an implicit base class.

Mule,

Yes I know that everything devises from Object and has a ToString but how
would one overload "int" in JScript in regards to the post presented by
Peter?

Does JScript take the "ToString" and then convert it to the type it needs?
That's awfully presumptuous!

Cal



Sat, 03 Jul 2004 02:18:25 GMT  
 please help :: button.click event

Quote:
> Yes I know that everything devises from Object and has a ToString but how
> would one overload "int" in JScript in regards to the post presented by
> Peter?

> Does JScript take the "ToString" and then convert it to the type it needs?
> That's awfully presumptuous!

Yes, that is what it does in late-bound scenarios. If JScript can't find a
better way to convert something into a primitive type, it first converts it
first to a string and then tries to convert the string to the primitive
type.

JScript will not allow this if it knows at compile-time that the LHS is an
integer (although you can of course do a cast to String and it will work
with a warning.)

Peter

--

Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
Please post all questions to the group. Thanks.



Sat, 03 Jul 2004 09:29:59 GMT  
 please help :: button.click event
If you wanted to, you could always implemenbt the IConvertable interface in
your object...That will allow you to convert it into any native type your
heart may desire.

Sean

Quote:

> Mule,

> Yes I know that everything devises from Object and has a ToString but how
> would one overload "int" in JScript in regards to the post presented by
> Peter?

> Does JScript take the "ToString" and then convert it to the type it needs?
> That's awfully presumptuous!

> Cal



Sat, 03 Jul 2004 11:48:04 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Help V4.0! Calling Button Click Event

2. Help: Listbox from DBGrid Button Click event.

3. Please Help: On Click event is not working

4. Please Help: On Click event is not working

5. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

6. Right Button Click emulating Left Button Click

7. Please Help: Enable a button during AddNew events?

8. Accessing the click event for a button on a custom form

9. Word com add-in and button click events

10. Calling MS-Word from button event click on outlook 98/2000

11. simulating cmd button click event

12. Button Click Event Not Firing !

 

 
Powered by phpBB® Forum Software