OK , toto su hlavne dva Sub-y v ktorych sa nastavuju Eventy , vytvaraju komponenty a podobne :
'''Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)'''
'create the containing table
Dim tbl As Table = New Table
tbl.Height = Me.Height
tbl.Width = Me.Width
tbl.ToolTip = Me.ToolTip
tbl.Style.Add("overflow", "scroll")
tbl.Style.Add("position", "absolute")
Dim td As TableCell = New TableCell
td.ColumnSpan = 2
td.Height = New Unit(95, UnitType.Percentage)
Dim tr As TableRow = New TableRow
tr.Cells.Add(td)
tbl.Rows.Add(tr)
'create the message display panel
_pnl.Width = New Unit(99, UnitType.Percentage)
_pnl.Height = New Unit(100, UnitType.Percentage)
_pnl.BorderStyle = WebControls.BorderStyle.Solid
_pnl.BorderWidth = New Unit(1, UnitType.Pixel)
_pnl.Style.Add(HtmlTextWriterStyle.Overflow, "scroll")
td.Controls.Add(_pnl)
'create a new table row for textbox & button
tr = New TableRow
tbl.Rows.Add(tr)
td = New TableCell
td.Width = New Unit(95, UnitType.Percentage)
tr.Cells.Add(td)
'create the button
Dim btn As Button = New Button
btn.ID = Me.ID & "_button"
btn.UseSubmitBehavior = False
btn.Text = "Send"
'create the textbox
_txt.Width = New Unit(99, UnitType.Percentage)
_txt.BorderColor = Drawing.Color.Black
_txt.BorderWidth = New Unit(1, UnitType.Pixel)
_txt.Attributes("autocomplete") = "off"
_txt.Attributes("onkeydown") = _
"if ((event.keyCode == 13)) {document.getElementById('" _
& btn.ClientID & _
"').click();return false;} else return true;"
_txt.Attributes("onkeypress") = "if (event.keyCode==124 || event.keyCode==126) event.keyCode=0;" 'prevent reserved (delimiter) characters from being entered
td.Controls.Add(_txt)
'create the final table cell
td = New TableCell
td.Controls.Add(btn)
tr.Cells.Add(td)
'Attach button's client event to the JavaScript functions
btn.Attributes("OnClick") = _
"DoChatCallBack(document.getElementById('" _
& _txt.ClientID & "'));"
tbl.RenderControl(output)
End Sub
Private Sub WebChat_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
_pnl.ID = Me.ID & "_chatpanel"
_txt.ID = Me.ID & "_chattextbox"
If Me.Visible Then
'Retrieve the JavaScript functions
'that will recieve the result
Dim sCallBack As String = _
My.Resources.Callback.Replace("WebChat1", Me.ID)
If Me.CallBackInterval <> 2 Then
sCallBack = sCallBack.Replace("2000", _
(Me.CallBackInterval * 1000).ToString())
End If
Page.ClientScript.RegisterClientScriptBlock(Me.GetType, _
"CalledBack", sCallBack, True)
'Now generate the function that initiates
'the client side callback
Dim sb As New StringBuilder()
sb.Append(System.Environment.NewLine)
sb.Append("function DoChatCallBack(txt)")
sb.Append(System.Environment.NewLine)
sb.Append("{")
sb.Append("var msg = ''; if (txt != null) msg=txt.value; ")
sb.Append(System.Environment.NewLine)
sb.Append(Page.ClientScript.GetCallbackEventReference(Me, _
"WebChatMaxMsgID + '||' + msg", _
"CalledBack", "ErrCalledBack"))
sb.Append(";")
sb.Append(System.Environment.NewLine)
sb.Append("if (txt != null) txt.value='';")
sb.Append(System.Environment.NewLine)
sb.Append("}")
Dim sDoCallBack As String = sb.ToString()
Page.ClientScript.RegisterClientScriptBlock(Me.GetType, _
"DoChatCallBack", sDoCallBack, True)
'set initial focus (if configured to do so)
If Me.InitialFocus AndAlso Me.Enabled Then
Page.ClientScript.RegisterStartupScript(Me.GetType, _
"ChatFocus", "document.getElementById('" _
& _txt.ClientID & "').focus();", True)
End If
'emit JavaScript function call that initializes
'the control and joins the user into the conversation
Page.ClientScript.RegisterStartupScript(Me.GetType, _
"ChatEnter", "ChatEnter();", True)
End If
End Sub
V Sub-e 'Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)' skoro na konci je tento kód ktory nastavy atributy aby po kliknuti sa vyvolal ten javascript kód :
'Attach button's client event to the JavaScript functions
btn.Attributes("OnClick") = _
"DoChatCallBack(document.getElementById('" _
& _txt.ClientID & "'));"
A tento kód :
"DoChatCallBack(document.getElementById('" _
& _txt.ClientID & "'));"
neviem spustit ako normal kód , teda ako ho mám vykonať napríklad v sub-e ? Vyzeralo by to asi takto ale pise to chybu :
Sub Send
"DoChatCallBack(document.getElementById('" _
& _txt.ClientID & "'));"
End Sub
|