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
    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,
    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)
    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
    dt = DataSource
    Catch ex As Exception
    ErrorState = ErrorsAllowed.NoDataSource
    End Try

    ssplit5 = Split(Page.Request.Params.Item("__EVENTTARGET"), ":")
    evt = ssplit5(0)
    Catch ex As Exception
    ErrorState = ErrorsAllowed.NoEventControlCaptured
    End 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
    For Each dr In dt.Rows
    If (Page.Request.Params.Item("__EVENTARGUMENT") = irow) Then
    RaiseEvent RowClicked(dr)
    Exit For
    irow = irow + 1
    End If
    Catch ex As Exception

    End Try

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

    End Try

    End If
    Dim wid As Integer
    For Each c In dt.Columns
    wid = wid + c.MaxLength
    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)
    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

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

    End Try
    For Each dr In dt.DefaultView.Table.Rows
    Dim ssplit As Object
    i = 0
    For Each c In dt.Columns
    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)
    Dim sw As New System.IO.StringWriter
    Dim hw As New System.Web.UI.HtmlTextWriter(sw)
    hw = Nothing
    sw = Nothing
    End If
    str.Append("</td>" & vbCrLf)
    End If
    i = i + 1
    Catch ex As Exception
    End Try
    str.Append("</tr>" & vbCrLf)
    irow = irow + 1
    str.Append("</table>" & vbCrLf)
    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
    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

    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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.