Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Hi Cannot Retain Attributes of Dynamic Controls

Reply
Thread Tools

Hi Cannot Retain Attributes of Dynamic Controls

 
 
milan04 milan04 is offline
Junior Member
Join Date: Mar 2011
Posts: 1
 
      03-27-2011
On button click i am creating a dyamic control

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Try
'create a new instance of the control
Dim new_button As Button = New Button()
new_button.ID = txtID.Text
new_button.ForeColor = System.Drawing.Color.FromName(txtForeColor.Text)
new_button.Text = txtText.Text
If (txtAttributes.Text = "onclick") Then
new_button.Attributes.Add("onclick", "alert('hi');")
End If
new_button.EnableViewState = True
'add button to button array
btn_arr(btn_count) = new_button
btn_count = btn_count + 1
'call our add function
lblStatus.Text &= "Created button " & new_button.ID & " and of color " & new_button.ForeColor.ToString()
pnlMain.Controls.Add(new_button)
'add a spacer after the control
pnlMain.Controls.Add(New LiteralControl("<br>"))
'add_button()
Catch ex As Exception
lblStatus.Text += ex.Message.ToString()
End Try
End Sub

And on PageLoad i am re-creating the control but my attributes are getting vanished on page load

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim Count As Integer
Count = 1
If TypeOf btn_arr(0) Is Button Then
'for each button saved in our array, recreate it
For Each button As Button In btn_arr
add_button(button)
If Count = btn_count Then
Exit For
End If
Count = Count + 1
Next button
End If
Catch ex As Exception
lblStatus.Text += ex.Message.ToString()
End Try


Protected Sub add_button(ByVal new_button As Button)
Try

'add to a container on the page
pnlMain.Controls.Add(new_button)
'add a spacer after the control
pnlMain.Controls.Add(New LiteralControl("<br>"))
Catch ex As Exception
lblStatus.Text += ex.Message.ToString()
End Try
End Sub

Please help me...
 
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
Problem with wireless connection - cannot get client ip, retain settings msabatini2001@yahoo.com Wireless Networking 0 08-15-2007 05:27 PM
Dynamic Controls created by Dynamic Controls Ronald ASP .Net 2 01-17-2006 12:44 AM
retain controls added to placeholder during postback? Mark ASP .Net 2 07-06-2004 05:53 PM
assign dynamic attributes in web controls in aspx file DCV via .NET 247 ASP .Net Web Controls 0 06-17-2004 10:35 PM
Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls Denny Smolinski via .NET 247 ASP .Net Web Controls 1 05-04-2004 09:15 PM



Advertisments