Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: accessing onCommand method


Message #1 by "Dave Fitzgerald" <david.fitzgerald@i...> on Mon, 4 Mar 2002 16:59:47
I am dynamically generating button controls on a panel control on a web 

form as shown:

            For Each aColorName In en.GetNames(en.GetType)

                Dim btn As New Button()

                btn.ID = aColorName

                btn.BackColor = System.Drawing.Color.FromName(aColorName)

                btn.CommandName = aColorName

                btn.CommandArgument = aColorName

                pnlColor.Controls.Add(btn)

            Next

I would like to access the button?s onCommand method programmatically.  

Can I? If so, How? If not,any suggestions would be helpful

Thanks 



Dave

Message #2 by "paulcr" <paulcr@c...> on Mon, 4 Mar 2002 18:39:04 -0000

Try adding:

 btn.OnCommand="aColorName_Command"

this will tie the event handler to the button object

Then create the event handler............

Sub aColorName_Command(sender As Object, e As CommandEventArgs)

'Do stuff in here ie....

myLabel.Text = e.CommandName & " = " & e.CommandArgument

End Sub



Hope this helps

>

> I am dynamically generating button controls on a panel control on a web

> form as shown:

>             For Each aColorName In en.GetNames(en.GetType)

>                 Dim btn As New Button()

>                 btn.ID = aColorName

>                 btn.BackColor = System.Drawing.Color.FromName(aColorName)

>                 btn.CommandName = aColorName

>                 btn.CommandArgument = aColorName

>                 pnlColor.Controls.Add(btn)

>             Next

> I would like to access the button's onCommand method programmatically.

> Can I? If so, How? If not,any suggestions would be helpful

> Thanks

>

> Dave

>

>





Message #3 by "david.fitzgerald" <david.fitzgerald@i...> on Tue, 5 Mar 2002 14:07:42 -0500
Thanks for the tip.  I cannot add the code as you suggested I receive the

following when attempting to either build and browse or just browse from

within VS.NET



error BC30390: 'System.Web.UI.WebControls.Button.Protected Overridable

Overloads Sub OnCommand(e As System.Web.UI.WebControls.CommandEventArgs)' is

not accessible in this context because it is 'Protected'.





Any suggestions?



-----Original Message-----

From: paulcr [mailto:paulcr@c...]

Sent: Monday, March 04, 2002 1:39 PM

To: aspx_beginners

Subject: [aspx_beginners] Re: accessing onCommand method





Try adding:

 btn.OnCommand="aColorName_Command"

this will tie the event handler to the button object

Then create the event handler............

Sub aColorName_Command(sender As Object, e As CommandEventArgs)

'Do stuff in here ie....

myLabel.Text = e.CommandName & " = " & e.CommandArgument

End Sub



Hope this helps

>

> I am dynamically generating button controls on a panel control on a web

> form as shown:

>             For Each aColorName In en.GetNames(en.GetType)

>                 Dim btn As New Button()

>                 btn.ID = aColorName

>                 btn.BackColor = System.Drawing.Color.FromName(aColorName)

>                 btn.CommandName = aColorName

>                 btn.CommandArgument = aColorName

>                 pnlColor.Controls.Add(btn)

>             Next

> I would like to access the button's onCommand method programmatically.

> Can I? If so, How? If not,any suggestions would be helpful

> Thanks

>

> Dave

>

>










$subst('Email.Unsub').

Message #4 by "paulcr" <paulcr@c...> on Tue, 5 Mar 2002 21:37:30 -0000

> Thanks for the tip.  I cannot add the code as you suggested I receive the

> following when attempting to either build and browse or just browse from

> within VS.NET

>

> error BC30390: 'System.Web.UI.WebControls.Button.Protected Overridable

> Overloads Sub OnCommand(e As System.Web.UI.WebControls.CommandEventArgs)'

is

> not accessible in this context because it is 'Protected'.

>

>

make your button bublic

Im not right into vb code syntax but try something like Dim Public btn As

New Button()





Message #5 by "Mark Robinson" <alltop@c...> on Tue, 5 Mar 2002 18:45:28 -0600

----- Original Message -----

From: "paulcr" <paulcr@c...>

Newsgroups: aspx_beginners

To: "aspx_beginners" <aspx_beginners@p...>

Sent: Tuesday, March 05, 2002 3:37 PM

Subject: [aspx_beginners] Re: accessing onCommand method





>

> > Thanks for the tip.  I cannot add the code as you suggested I receive

the

> > following when attempting to either build and browse or just browse from

> > within VS.NET

> >

> > error BC30390: 'System.Web.UI.WebControls.Button.Protected Overridable

> > Overloads Sub OnCommand(e As

System.Web.UI.WebControls.CommandEventArgs)'

> is

> > not accessible in this context because it is 'Protected'.

> >

> >

> make your button bublic

> Im not right into vb code syntax but try something like Dim Public btn As

> New Button()

>

>

>




$subst('Email.Unsub').

>



Message #6 by "Mark Robinson" <alltop@c...> on Tue, 5 Mar 2002 18:45:18 -0600

----- Original Message -----

From: "david.fitzgerald" <david.fitzgerald@i...>

To: "aspx_beginners" <aspx_beginners@p...>

Sent: Tuesday, March 05, 2002 1:07 PM

Subject: [aspx_beginners] Re: accessing onCommand method





> Thanks for the tip.  I cannot add the code as you suggested I receive the

> following when attempting to either build and browse or just browse from

> within VS.NET

>

> error BC30390: 'System.Web.UI.WebControls.Button.Protected Overridable

> Overloads Sub OnCommand(e As System.Web.UI.WebControls.CommandEventArgs)'

is

> not accessible in this context because it is 'Protected'.

>

>

> Any suggestions?

>

> -----Original Message-----

> From: paulcr [mailto:paulcr@c...]

> Sent: Monday, March 04, 2002 1:39 PM

> To: aspx_beginners

> Subject: [aspx_beginners] Re: accessing onCommand method

>

>

> Try adding:

>  btn.OnCommand="aColorName_Command"

> this will tie the event handler to the button object

> Then create the event handler............

> Sub aColorName_Command(sender As Object, e As CommandEventArgs)

> 'Do stuff in here ie....

> myLabel.Text = e.CommandName & " = " & e.CommandArgument

> End Sub

>

> Hope this helps

> >

> > I am dynamically generating button controls on a panel control on a web

> > form as shown:

> >             For Each aColorName In en.GetNames(en.GetType)

> >                 Dim btn As New Button()

> >                 btn.ID = aColorName

> >                 btn.BackColor 

System.Drawing.Color.FromName(aColorName)

> >                 btn.CommandName = aColorName

> >                 btn.CommandArgument = aColorName

> >                 pnlColor.Controls.Add(btn)

> >             Next

> > I would like to access the button's onCommand method programmatically.

> > Can I? If so, How? If not,any suggestions would be helpful

> > Thanks

> >

> > Dave

> >

> >

>

>

>




> $subst('Email.Unsub').

>




$subst('Email.Unsub').




  Return to Index