Results 1 to 2 of 2

Thread: WebParts and MOSS 2007

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    2

    WebParts and MOSS 2007

    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:

    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

    Thanks!

  2. #2

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    2

    Re: WebParts and MOSS 2007

    Okay, found a partial solution.

    As it turns out there are some things that are not needed with the code: The RenderControls procedure needs to be taken right out. Also, I have noticed through examples this code:

    <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _

    applied to the beginning of the webpart class. Is it needed? I am not sure, but since my webpart works now, I left it in. Btw, to use the above tags, be sure to import System.Security.Permissions

    Now, the next thing is to work with the SelectedIndexChanged event. These seem to be causing errors.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width