masonstjon
New member
- Joined
- Feb 2, 2007
- Messages
- 2
- Programming Experience
- Beginner
Okay...I have succesfully created and added a webpart programmically to MOSS 2007 (thank you Sahil Malik!!). The webpart displays a label and a button. However, when I click the button, the label is supposed to change from "Hello" to "Goodbye". The page reloads as though it went back to the server to find code for the click event, but the label does not change. Any help would be appreciated on this. If the solution deals with IPostBackEventHandler and its subsequent RaisePostBackEvent method, then can someone describe how to use this. Here's the code:
Thanks!
VB.NET:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Serialization
Imports System.Runtime.InteropServices
Imports System.Security
Imports System.Security.Permissions
<DefaultProperty("Text"), ToolboxData("<{0}:Test runat=server></{0}:WebCustomControl1>")> _
Public Class Test
Inherits WebPart
Dim lbl As New Label
Dim btn As New Button
<Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)> Protected Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
lbl.Text = "Hello"
btn.Text = "Click Me"
btn.ID = "Test"
AddHandler btn.Click, AddressOf btn_Click
Controls.Add(lbl)
Controls.Add(btn)
End Sub
Protected Sub btn_Click(ByVal s As Object, ByVal e As EventArgs)
lbl.Text = "Goodbye"
End Sub
Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)
CreateChildControls()
lbl.RenderControl(output)
btn.RenderControl(output)
End Sub
End Class
Last edited by a moderator: