By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,958 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,958 IT Pros & Developers. It's quick & easy.

Addhnadler postback problem....plz help asap...

P: 3
Hi,
I have created some dynamic labels and some dynamic linkbuttons... those linkbuttons have addhandlers assigned to them... but in postback those buttons gets deleted...

the code is shown below... plz help asap...
Expand|Select|Wrap|Line Numbers
  1.     Dim conn As New Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
  2.     Dim itable As New Table
  3.     Dim irow As New TableRow
  4.     Dim icell(5), ic(5) As TableCell
  5.     Dim txt As New Label
  6.     Dim prd, sku As Label
  7.     Dim tit As TextBox
  8.     Dim skus As Label
  9.     Dim upd, del As LinkButton
  10.     Dim ic1(7), ic2(7) As TableCell
  11.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  12.         If Not Page.IsPostBack Then
  13.             Dim ds As New Data.DataSet
  14.             Dim select_cat As Data.OleDb.OleDbDataAdapter
  15.             select_cat = New Data.OleDb.OleDbDataAdapter("select name from category order by pos", conn)
  16.             select_cat.Fill(ds, "name")
  17.             catitems.DataSource = ds.Tables(0).DefaultView
  18.             catitems.DataBind()
  19.         End If
  20.         If Page.IsPostBack Then
  21.             plc.Controls.Clear()
  22.             Call headdel()
  23.             Call get_deldata()
  24.         End If
  25.     End Sub
  26.  
  27.     Protected Sub catitems_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles catitems.SelectedIndexChanged
  28.         txt.Text = catitems.SelectedValue
  29.         Call headdel()
  30.     End Sub
  31.     Sub headdel()
  32.         Dim edi, delet, zon, clas As Label
  33.         Dim a As Integer
  34.         For a = 0 To 5
  35.             zon = New Label
  36.             zon.Text = "Product title"
  37.             clas = New Label
  38.             clas.Text = "SKU"
  39.             icell(a) = New TableCell
  40.             edi = New Label
  41.             edi.Text = "Update"
  42.             delet = New Label
  43.             delet.Text = "Delete"
  44.             If a = 0 Then
  45.                 icell(a).Controls.Add(zon)
  46.             End If
  47.             If a = 1 Then
  48.                 icell(a).Controls.Add(clas)
  49.             End If
  50.             If a = 2 Then
  51.                 icell(a).Controls.Add(edi)
  52.             End If
  53.             If a = 3 Then
  54.                 icell(a).Controls.Add(delet)
  55.             End If
  56.         Next
  57.         itable = New Table
  58.         irow = New TableRow
  59.         irow.BorderWidth = 1
  60.         itable.BorderWidth = 1
  61.         itable.Width = 650
  62.         irow.BorderWidth = 1
  63.         itable.Rows.Add(irow)
  64.         irow.Cells.Add(icell(0))
  65.         irow.Cells.Add(icell(1))
  66.         irow.Cells.Add(icell(2))
  67.         irow.Cells.Add(icell(3))
  68.         'plc.Controls.Add(itable)
  69.         Call get_deldata()
  70.     End Sub
  71.     Sub get_deldata()
  72.         Dim conn As New Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
  73.         Dim comm As New Data.OleDb.OleDbCommand
  74.         Dim reader As Data.OleDb.OleDbDataReader
  75.         Dim state As String
  76.         Dim b As Integer
  77.         conn.Open()
  78.         state = "select [title],sku from products where cat='" & txt.Text & "'"
  79.         comm = New Data.OleDb.OleDbCommand(state, conn)
  80.         reader = comm.ExecuteReader
  81.         While reader.Read
  82.             irow = New TableRow
  83.             itable.Rows.Add(irow)
  84.             prd = New Label
  85.             sku = New Label
  86.             ic1(0) = New TableCell
  87.             prd.Text = reader.GetValue(0)
  88.             ic1(0).Controls.Add(prd)
  89.             ic1(1) = New TableCell
  90.             sku.Text = reader.GetValue(1)
  91.             ic1(1).Controls.Add(sku)
  92.             itable.Rows.Add(irow)
  93.             irow.Cells.Add(ic1(0))
  94.             irow.Cells.Add(ic1(1))
  95.             Dim conn1 As New Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
  96.             Dim comm1 As New Data.OleDb.OleDbCommand
  97.             Dim reader1 As Data.OleDb.OleDbDataReader
  98.             Dim state1 As String
  99.             conn1.Open()
  100.             state1 = "select [sku],[prdtitle],[ID] from [prdfake] where [sku]='" & reader.GetValue(1) & "'"
  101.             comm1 = New Data.OleDb.OleDbCommand(state1, conn1)
  102.             reader1 = comm1.ExecuteReader
  103.             While reader1.Read
  104.                 upd = New LinkButton
  105.                 upd.Text = "Update"
  106.                 'AddHandler upd.Click, AddressOf updbtn
  107.                 'upd.ID = "ty" & reader.GetValue(1)
  108.                 del = New LinkButton
  109.                 del.Text = "Delete"
  110.                 del.ID = "dt" & reader1.GetValue(0)
  111.                 AddHandler del.Click, AddressOf delbtn
  112.                 For b = 0 To 5
  113.                     tit = New TextBox
  114.                     tit.Text = reader1.GetValue(1)
  115.                     skus = New Label
  116.                     skus.Text = reader1.GetValue(0)
  117.                     ic2(b) = New TableCell
  118.                     If b = 0 Then
  119.                         ic2(b).Controls.Add(tit)
  120.                         ic2(b).Width = "100"
  121.                     End If
  122.                     If b = 1 Then
  123.                         ic2(b).Controls.Add(skus)
  124.                         ic2(b).Width = "100"
  125.                     End If
  126.                     If b = 2 Then
  127.                         ic2(b).Controls.Add(upd)
  128.                         ic2(b).Width = "50"
  129.                     End If
  130.                     If b = 3 Then
  131.                         ic2(b).Controls.Add(del)
  132.                         ic2(b).Width = "150"
  133.                     End If
  134.                 Next
  135.                 irow = New TableRow
  136.                 itable.Rows.Add(irow)
  137.                 irow.Cells.Add(ic2(0))
  138.                 irow.Cells.Add(ic2(1))
  139.                 irow.Cells.Add(ic2(2))
  140.                 irow.Cells.Add(ic2(3))
  141.             End While
  142.             conn1.Close()
  143.             comm1.Dispose()
  144.             conn1.Dispose()
  145.             Dim add As LinkButton
  146.             add = New LinkButton
  147.             add.ID ="a" & reader.GetValue(1)
  148.             add.Text = "Add new title"
  149.             AddHandler add.Click, AddressOf show
  150.             ic2(4) = New TableCell
  151.             ic2(4).Controls.Add(add)
  152.             ic2(4).Width = "100"
  153.             irow.Cells.Add(ic2(4))
  154.         End While
  155.         conn.Close()
  156.         comm.Dispose()
  157.         conn.Dispose()
  158.         plc.Controls.Add(itable)
  159.     End Sub
  160.     Public Sub show(ByVal sender As Object, ByVal e As EventArgs)
  161.         Call headdel()
  162.         Call get_deldata()
  163.     End Sub
  164.     Public Sub delbtn(ByVal sender As Object, ByVal e As EventArgs)
  165.         Dim t As Integer = sender.ToString.Length
  166.         Dim conn3 As New Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
  167.         Dim comm3 As New Data.OleDb.OleDbCommand
  168.         Dim state3 As String
  169.         Try
  170.             Dim t1 As New Label
  171.             t1.Text = "Product Title"
  172.             state3 = "insert into [prdfake]([sku],[prdtitle]) values('" & t1.Text & "','" & t1.Text & "')"
  173.             comm3 = New Data.OleDb.OleDbCommand(state3, conn3)
  174.             conn3.Open()
  175.             comm3.ExecuteNonQuery()
  176.         Catch ex As Exception
  177.             Response.Write(ex.Message)
  178.         Finally
  179.             If Not conn3 Is Nothing Then
  180.                 conn3.Close()
  181.             End If
  182.             conn3.Dispose()
  183.             comm3.Dispose()
  184.             Call headdel()
  185.         End Try
  186.     End Sub
Aug 31 '08 #1
Share this Question
Share on Google+
3 Replies


joedeene
100+
P: 583
please remember to use <code> tages (the '#' button after selecting your code you pasted into the post)

joedeene
Aug 31 '08 #2

P: 3
plz help me wid this........
Aug 31 '08 #3

Curtis Rutland
Expert 2.5K+
P: 3,256
joedeene asked you once to use code tags. I've deleted your other post where you just re-paste your code.

Please read the Posting Guidelines.

MODERATOR
Sep 1 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.