Events Events Events Please Help

Discussion in 'ASP .Net Web Controls' started by Chris, Aug 30, 2005.

  1. Chris

    Chris Guest

    Hello Everybody,
    I would like to start off saying thank you for helping.

    Ok the Issue. I can not get an event to fire from a programmelity added
    button from a web control library
    What I want to have happen
    I need to have a web control library which inherits
    system.web.ui.webcontrols.webcontrol
    I Then need to create a datagrid from html code<-- No overhead of the
    microsoft datagrid. about 2 times faster with displaying data.
    I Then need to create a ASP:button inside that datagrid(from html code).

    Getting everything to display is done in the code below. Getting the event
    to fire on the <ASP: button I am pulling my hair out.
    I have tryed the IPostBackEventdata,
    raiseUPBubbleEvent,
    I have tryed addhandler.
    I have tryed to addhandler to the parent page with the addressof
    webcontrolibrary.onclick event

    I can not get anything to raise event on the webcontrol library.

    So this is the code from the IPostBackEventData. The reason I am still using
    this is because I have found a workaround for the time

    So the code is as:

    I have a web form.
    Code:: You will see the HOKEY workaround that I did to get this to work
    Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
    Try
    Dim c As New System.Data.DataColumn
    Dim str As New StringBuilder
    Dim html As HtmlTextWriter
    Dim i, i2 As Integer
    Dim drholder() As DataRow
    Dim dr As DataRow
    html = output
    MyBase.EnableViewState = True
    Dim irow As Integer
    Dim evt As String
    Dim ssplit5 As Object
    Dim ctl As String
    Try
    dt = DataSource
    Catch ex As Exception
    ErrorState = ErrorsAllowed.NoDataSource
    End Try

    Try
    ssplit5 = Split(Page.Request.Params.Item("__EVENTTARGET"), ":")
    evt = ssplit5(0)
    Catch ex As Exception
    ErrorState = ErrorsAllowed.NoEventControlCaptured
    End Try
    Try
    ssplit5 = Split(Me.UniqueID, ":")
    ctl = ssplit5(0)
    Catch ex As Exception
    ErrorState = ErrorsAllowed.UniqueIdNotFound
    End Try


    If (LCase(evt) = LCase(Left(Me.UniqueID, Len(evt)))) Then
    irow = 0
    Try
    For Each dr In dt.Rows
    If (Page.Request.Params.Item("__EVENTARGUMENT") = irow) Then
    RaiseEvent RowClicked(dr)
    Exit For
    Else
    irow = irow + 1
    End If
    Next
    Catch ex As Exception

    End Try

    Try
    For Each c In dt.Columns
    If (Page.Request.Params.Item("__EVENTARGUMENT") =
    c.ColumnName.ToString) Then
    passin = c.ColumnName.ToString
    Exit For
    Else
    passin = ""
    End If
    Next
    Catch ex As Exception

    End Try

    End If
    Dim wid As Integer
    For Each c In dt.Columns
    wid = wid + c.MaxLength
    Next
    str.Append("<script language=""javascript""> function rowSelect(row,col)
    { } function sort(cn) { } function EditThis(button,value) { }" & vbCrLf)
    str.Append("</script>" & vbCrLf)
    str.Append("<DIV id=""gridMain"" style="" HEIGHT: 300px"">" & vbCrLf)
    str.Append("<Table width=""" & wid & """ border=""1"" cellpadding=""0""
    cellspacing=""0"" ><tr>" & vbCrLf)
    For Each c In dt.Columns
    str.Append("<td align=""Left"" width=""" & c.MaxLength & """ ><a
    href=""#"" onclick=""JavaScript:" & Page.GetPostBackEventReference(Me,
    c.ColumnName.ToString) & ";"">" & vbCrLf)
    str.Append(c.ColumnName.ToString & vbCrLf)
    str.Append("</a></td>" & vbCrLf)
    Next
    str.Append("</tr></table>" & vbCrLf)
    str.Append("<DIV id=""grid"" style=""OVERFLOW: auto; HEIGHT:
    250px""><table border=""1"" width=""" & wid & """ cellpadding=""0""
    cellspacing=""0"">" & vbCrLf)

    irow = 0
    Dim icol As Integer
    icol = dt.Columns.Count
    Try


    If (Len(Trim(passin)) <> 0) Then
    dt.DefaultView.Sort = passin & " DESC"
    Else
    dt.DefaultView.Sort = "Desc"
    End If
    Catch ex As Exception

    End Try
    For Each dr In dt.DefaultView.Table.Rows
    str.Append("<tr>")
    Dim ssplit As Object
    i = 0
    For Each c In dt.Columns
    Try
    ssplit = Split(dr.Item(i), "!")
    str.Append("<td align=""Left"" onclick=""Javascript: rowSelect(" &
    irow.ToString & "," & icol.ToString & ");"" id=""" & irow.ToString & "," &
    icol.ToString & """ width=""" & c.MaxLength & """>" & vbCrLf)
    If (UBound(ssplit) = 1) Then
    If (ssplit(0) = "~BUTTON") Then
    Dim ssplit2 As Object
    ssplit2 = Split(dr.Item(6), "!")
    btn.Attributes.Add("BtnValue", ssplit2(0))
    Dim e As New System.EventArgs
    b = New MyButton(ssplit2(0), irow)
    MyBase.Parent.Controls.Add(b)
    Dim sw As New System.IO.StringWriter
    Dim hw As New System.Web.UI.HtmlTextWriter(sw)
    b.RenderControl(hw)
    str.Append(sw)
    hw.Close()
    hw = Nothing
    sw.Close()
    sw = Nothing
    Else
    str.Append(ssplit(0))
    End If
    str.Append("</td>" & vbCrLf)
    End If
    i = i + 1
    Catch ex As Exception
    End Try
    Next
    str.Append("</tr>" & vbCrLf)
    irow = irow + 1
    Next
    str.Append("</table>" & vbCrLf)
    output.Write(str.ToString)
    output.Write("</div></div>" & vbCrLf)
    Catch ex As Exception

    End Try

    End Sub





    I have a web control library
    My web control library inherits system.web.ui.webcontrols.webcontrol

    Inside my webcontrol I have 2 classes
    ofcourse I have my base class of the webcontrol
    Then I have another class called MyButton
    The Class of MyButton is as
    Public Class MyButton
    Inherits Control
    Implements IPostBackDataHandler
    Implements IPostBackEventHandler

    Public Event Click As EventHandler
    Protected Overridable Sub OnClick(ByVal e As EventArgs)
    RaiseEvent Click(Me, e)
    End Sub

    Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements
    IPostBackEventHandler.RaisePostBackEvent
    OnClick(EventArgs.Empty)
    End Sub

    Dim buttonkeeper As String
    Dim irow As String
    Public Sub New(ByVal buttonValue As String, ByVal row As String)
    buttonkeeper = buttonValue
    irow = row
    End Sub

    Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
    output.Write("<INPUT TYPE=submit OnClick=""JavaScript:" &
    Page.GetPostBackEventReference(Me, irow) & ";"" name=" & Me.UniqueID & "
    row="" & irow & "" Value='Edit' />")

    End Sub

    Public Function LoadPostData(ByVal postDataKey As String, ByVal
    postCollection As System.Collections.Specialized.NameValueCollection) As
    Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData

    End Function

    Public Sub RaisePostDataChangedEvent() Implements
    System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent

    End Sub

    End Class

    As you can see from the class above it is just a class that inherits Control
    Chris, Aug 30, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JC
    Replies:
    4
    Views:
    7,938
    Jeff C
    Jul 8, 2004
  2. Replies:
    4
    Views:
    484
    Chris Uppal
    May 5, 2005
  3. KK
    Replies:
    2
    Views:
    496
    Big Brian
    Oct 14, 2003
  4. MuZZy
    Replies:
    7
    Views:
    1,709
    Mike Hewson
    Jan 7, 2005
  5. mera
    Replies:
    7
    Views:
    1,066
Loading...

Share This Page