Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > How to execute operations on dynamic objects?

Reply
Thread Tools

How to execute operations on dynamic objects?

 
 
Robson Carvalho Machado
Guest
Posts: n/a
 
      08-07-2004
Dear friends,

I've created a new label and a new Button on my form using the above code.

Dim myLabel As Label
myLabel = New Label
myLabel.ID = "label1"
myLabel.Text = "Dynamic button test"
myLabel.Attributes("style") = "position:absolute;top:150px;left:100px"
PlaceHolder1.Controls.Add(myLabel)

Dim myButton As Button
myButton = New Button
myButton.ID = "Button1"
myButton.Text = "OK"
myButton.Attributes("style") =
"position:absolute;top:150px;left:150px"
PlaceHolder1.Controls.Add(myButton)


How can I set the actions executed on button1_Click event?

I've tried the following but it does not work:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
label1.Text = "Button Click"
End Sub
 
Reply With Quote
 
 
 
 
Juno
Guest
Posts: n/a
 
      08-07-2004
Hi,

Using AddHandler statement:

AddHandler myButton .Click, AddressOf Button1_Click

--
Juno
MCSD.NET, MCDBA, MCSE
----------------------------------------------------------
Support Team of EasyDotNet, INC. http://www.EasyDotNet.com
DataForm.NET - The most powerful data entry web server control for ASP.NET



"Robson Carvalho Machado" <(E-Mail Removed) >
wrote in message news:(E-Mail Removed)...
> Dear friends,
>
> I've created a new label and a new Button on my form using the above code.
>
> Dim myLabel As Label
> myLabel = New Label
> myLabel.ID = "label1"
> myLabel.Text = "Dynamic button test"
> myLabel.Attributes("style") =

"position:absolute;top:150px;left:100px"
> PlaceHolder1.Controls.Add(myLabel)
>
> Dim myButton As Button
> myButton = New Button
> myButton.ID = "Button1"
> myButton.Text = "OK"
> myButton.Attributes("style") =
> "position:absolute;top:150px;left:150px"
> PlaceHolder1.Controls.Add(myButton)
>
>
> How can I set the actions executed on button1_Click event?
>
> I've tried the following but it does not work:
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> label1.Text = "Button Click"
> End Sub



 
Reply With Quote
 
 
 
 
Robson Carvalho Machado
Guest
Posts: n/a
 
      08-07-2004
Hi Juno

It works with

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Response.Write("Button Click")
End Sub

but does not work with .....

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
label1.Text = "Button Click"
End Sub

Once label1 is dynamic created

I'm receiving the following error message:

Name label1.Text is not declared

Can You help-me with the complete code to interact this two objects?

"Juno" wrote:

> Hi,
>
> Using AddHandler statement:
>
> AddHandler myButton .Click, AddressOf Button1_Click
>
> --
> Juno
> MCSD.NET, MCDBA, MCSE
> ----------------------------------------------------------
> Support Team of EasyDotNet, INC. http://www.EasyDotNet.com
> DataForm.NET - The most powerful data entry web server control for ASP.NET
>
>
>
> "Robson Carvalho Machado" <(E-Mail Removed) >
> wrote in message news:(E-Mail Removed)...
> > Dear friends,
> >
> > I've created a new label and a new Button on my form using the above code.
> >
> > Dim myLabel As Label
> > myLabel = New Label
> > myLabel.ID = "label1"
> > myLabel.Text = "Dynamic button test"
> > myLabel.Attributes("style") =

> "position:absolute;top:150px;left:100px"
> > PlaceHolder1.Controls.Add(myLabel)
> >
> > Dim myButton As Button
> > myButton = New Button
> > myButton.ID = "Button1"
> > myButton.Text = "OK"
> > myButton.Attributes("style") =
> > "position:absolute;top:150px;left:150px"
> > PlaceHolder1.Controls.Add(myButton)
> >
> >
> > How can I set the actions executed on button1_Click event?
> >
> > I've tried the following but it does not work:
> >
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs)
> > label1.Text = "Button Click"
> > End Sub

>
>
>

 
Reply With Quote
 
Jos
Guest
Posts: n/a
 
      08-07-2004
Robson Carvalho Machado wrote:
> Hi Juno
>
> It works with
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> Response.Write("Button Click")
> End Sub
>
> but does not work with .....
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> label1.Text = "Button Click"
> End Sub
>
> Once label1 is dynamic created
>
> I'm receiving the following error message:
>
> Name label1.Text is not declared
>
> Can You help-me with the complete code to interact this two objects?


Don't use label1.Text, but use the variable name that you assigned:

myLabel.Text = "Button Click"

You'll have to declare myLabel as a class member, not as a
local variable.

The variable name for a static control is the same as its ID.
This is not true for a dynamic control.

--

Jos


 
Reply With Quote
 
Robson Carvalho Machado
Guest
Posts: n/a
 
      08-07-2004
Dear Jos,

Unfortunely it still not working.

My complete code looks like code above.
Please, can you correct what I did wrong?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim myLabel As Label
myLabel = New Label
myLabel.ID = "label1"
myLabel.Text = "Dynamic button test"
myLabel.Attributes("style") = "position:absolute;top:150px;left:100px"
PlaceHolder1.Controls.Add(myLabel)

Dim myButton As Button
myButton = New Button
myButton.ID = "Button1"
myButton.Text = "OK"
myButton.Attributes("style") =
"position:absolute;top:170px;left:100px"
PlaceHolder1.Controls.Add(myButton)
With myButton
AddHandler .Click, AddressOf Button1_Click
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
myLabel.text = "Button Clicked"
End Sub



"Jos" wrote:

> Robson Carvalho Machado wrote:
> > Hi Juno
> >
> > It works with
> >
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs)
> > Response.Write("Button Click")
> > End Sub
> >
> > but does not work with .....
> >
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs)
> > label1.Text = "Button Click"
> > End Sub
> >
> > Once label1 is dynamic created
> >
> > I'm receiving the following error message:
> >
> > Name label1.Text is not declared
> >
> > Can You help-me with the complete code to interact this two objects?

>
> Don't use label1.Text, but use the variable name that you assigned:
>
> myLabel.Text = "Button Click"
>
> You'll have to declare myLabel as a class member, not as a
> local variable.
>
> The variable name for a static control is the same as its ID.
> This is not true for a dynamic control.
>
> --
>
> Jos
>
>
>

 
Reply With Quote
 
Robson Carvalho Machado
Guest
Posts: n/a
 
      08-07-2004
Dear Jos,

I'm sorry, I didn't saw your comments about transfer declaration to class
area.

Now it worked fine.

Thanks a Lot.

"Robson Carvalho Machado" wrote:

> Dear Jos,
>
> Unfortunely it still not working.
>
> My complete code looks like code above.
> Please, can you correct what I did wrong?
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> Dim myLabel As Label
> myLabel = New Label
> myLabel.ID = "label1"
> myLabel.Text = "Dynamic button test"
> myLabel.Attributes("style") = "position:absolute;top:150px;left:100px"
> PlaceHolder1.Controls.Add(myLabel)
>
> Dim myButton As Button
> myButton = New Button
> myButton.ID = "Button1"
> myButton.Text = "OK"
> myButton.Attributes("style") =
> "position:absolute;top:170px;left:100px"
> PlaceHolder1.Controls.Add(myButton)
> With myButton
> AddHandler .Click, AddressOf Button1_Click
> End With
> End Sub
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> myLabel.text = "Button Clicked"
> End Sub
>
>
>
> "Jos" wrote:
>
> > Robson Carvalho Machado wrote:
> > > Hi Juno
> > >
> > > It works with
> > >
> > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs)
> > > Response.Write("Button Click")
> > > End Sub
> > >
> > > but does not work with .....
> > >
> > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs)
> > > label1.Text = "Button Click"
> > > End Sub
> > >
> > > Once label1 is dynamic created
> > >
> > > I'm receiving the following error message:
> > >
> > > Name label1.Text is not declared
> > >
> > > Can You help-me with the complete code to interact this two objects?

> >
> > Don't use label1.Text, but use the variable name that you assigned:
> >
> > myLabel.Text = "Button Click"
> >
> > You'll have to declare myLabel as a class member, not as a
> > local variable.
> >
> > The variable name for a static control is the same as its ID.
> > This is not true for a dynamic control.
> >
> > --
> >
> > Jos
> >
> >
> >

 
Reply With Quote
 
Robson Carvalho Machado
Guest
Posts: n/a
 
      08-07-2004
Dear Friends,

I have the following code that creates dynamic controls at my form.

My dificult is how to correct this code to put distinct AddHandler to each
button and how to choose what label will receive text when Button1 is
clickedor Button2 is clicked.

I want to make possible to change text on Label1 when Button1 is clicked and
change text on Label2 when Button2 is clicked .. and so on...

Regards
Robson Machado

ASPX CODE:
---------------
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="dynamic.aspx.vb"
Inherits="corretoresdeseguros.dynamic"%>
<HTML>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asplaceHolder id="PlaceHolder1" runat="server"></asplaceHolder>
</form>
</body>
</HTML>


CODEBEHIND:
----------------

Public Class dynamic
Inherits System.Web.UI.Page
Dim myLabel As Label
Dim myRadio As RadioButtonList
Dim myRFV As RequiredFieldValidator
Dim myText As TextBox
Dim myButton As Button
Dim myUnits As System.Web.UI.WebControls.Unit

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
AddControls(1, 1, "Label1", "Label")
AddControls(1, 2, "Label2", "Label")
AddControls(1, 1, "Button1", "Button")
AddControls(1, 2, "Button2", "Button")
End Sub
Sub AddControls(ByVal Index As Integer, ByVal QNum As Long, ByVal
LabelText As String, ByVal Type As String)
If Type = "Label" Then
' Add Label
myLabel = New Label
myLabel.ID = "LabelQ" & QNum
myLabel.Text = LabelText & "<br><br>"
myLabel.BorderStyle = 2
PlaceHolder1.Controls.Add(myLabel)
End If

If Type = "Radio" Then
' Add Radio
myRadio = New RadioButtonList
myRadio.ID = "RadioQ" & QNum
myRadio.Items.Add("0")
myRadio.Items.Add("1")
myRadio.Items.Add("2")
myRadio.Items.Add("3")
myRadio.Items.Add("4")
myRadio.Items.Add("5")
myUnits = New System.Web.UI.WebControls.Unit(402)
myRadio.Width = myUnits
myRadio.RepeatDirection = 0
PlaceHolder1.Controls.Add(myRadio)
End If

If Type = "RFV" Then
' Add RFV
myRFV = New RequiredFieldValidator
myRFV.ID = "RFVQ" & QNum
myRFV.ErrorMessage = "Unanswered"
myRFV.ControlToValidate = "RadioQ" & QNum
PlaceHolder1.Controls.Add(myRFV)
End If

If Type = "Button" Then
myButton = New Button
myButton.ID = "Button" & QNum
myButton.Text = LabelText
PlaceHolder1.Controls.Add(myButton)
With myButton
AddHandler .Click, AddressOf Button1_Click
End With
End If

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
myLabel.Text = "Button Clicked"
End Sub
End Class


"Jos" wrote:

> Robson Carvalho Machado wrote:
> > Hi Juno
> >
> > It works with
> >
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs)
> > Response.Write("Button Click")
> > End Sub
> >
> > but does not work with .....
> >
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs)
> > label1.Text = "Button Click"
> > End Sub
> >
> > Once label1 is dynamic created
> >
> > I'm receiving the following error message:
> >
> > Name label1.Text is not declared
> >
> > Can You help-me with the complete code to interact this two objects?

>
> Don't use label1.Text, but use the variable name that you assigned:
>
> myLabel.Text = "Button Click"
>
> You'll have to declare myLabel as a class member, not as a
> local variable.
>
> The variable name for a static control is the same as its ID.
> This is not true for a dynamic control.
>
> --
>
> Jos
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Problem understanding how to make a dynamic GridView execute Update on SqlDataSource PeterKellner ASP .Net Datagrid Control 1 06-02-2006 11:59 AM
stand-alone JMS, other JDBC operations, and transactions ( ActiveMQ + JOTM + JDBC operations ) Jesus M. Salvo Jr. Java 2 02-11-2006 06:33 PM
Can i execute aspx file in my asp pag with server.execute method(sorry) Savas Ates ASP General 1 08-17-2004 04:52 PM
Mathematical Operations in VHDL MtnSurf8 VHDL 1 04-25-2004 06:07 AM



Advertisments