Web Parts - ASP.NET 2.0

R

RhondaT

Working thru the 'step by step' book... Chpter 7. I even tried using the
sample code. (OK, I'm a VB person, not C#... but that shouldn't matter) For
some reason, the 'design' mode is NOT enabled... so when I run the page, my
dropdown list only contains 'browse'. If I over-ride the check, the 'design'
option shows in the list, but does not function properly. Setting the break
point shows that the design mode is not enabled... *where* is it not
enabled, and how do I enable it?

Thanks!
 
R

RhondaT

perhaps this might help in the discussion :

default.aspx code:
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:WebPartManager ID="WebPartManager1" runat="server">
</asp:WebPartManager>
<asp:Label ID="Label1" runat="server" Text="Switch Display
Mode:"></asp:Label><br />
<asp:DropDownList ID="DropDownListDisplayModes" runat="server"
AutoPostBack="True"

OnSelectedIndexChanged="DropDownListDisplayModes_SelectedIndexChanged">
</asp:DropDownList><br />

</div>
<asp:WebPartZone ID="WebPartZoneLinks" runat="server"
BorderColor="#CCCCCC" Font-Names="Verdana"
HeaderText="Links" Padding="6" Width="223px">
<EmptyZoneTextStyle Font-Size="0.8em" />
<PartStyle Font-Size="0.8em" ForeColor="#333333" />
<TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False"
ForeColor="White" />
<MenuLabelHoverStyle ForeColor="#E2DED6" />
<MenuPopupStyle BackColor="#5D7B9D" BorderColor="#CCCCCC"
BorderWidth="1px" Font-Names="Verdana"
Font-Size="0.6em" />
<MenuVerbStyle BorderColor="#5D7B9D" BorderStyle="Solid"
BorderWidth="1px" ForeColor="White" />
<PartTitleStyle BackColor="#5D7B9D" Font-Bold="True"
Font-Size="0.8em" ForeColor="White" />
<ZoneTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="http://msdn.mirosoft.com">MSDN</asp:HyperLink>
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="http://www.syncfusioin.com">Syncfusion</asp:HyperLink>
<asp:HyperLink ID="HyperLink3" runat="server"
NavigateUrl="http://www.microsoft.com">Microsoft</asp:HyperLink>
</ZoneTemplate>
<MenuVerbHoverStyle BackColor="#F7F6F3" BorderColor="#CCCCCC"
BorderStyle="Solid"
BorderWidth="1px" ForeColor="#333333" />
<PartChromeStyle BackColor="#F7F6F3" BorderColor="#E2DED6"
Font-Names="Verdana" ForeColor="White" />
<HeaderStyle Font-Size="0.7em" ForeColor="Blue"
HorizontalAlign="Center" />
<MenuLabelStyle ForeColor="White" />
</asp:WebPartZone>

</form>
</body>
</html>


default.aspx.vb code:
Partial Class _Default
Inherits System.Web.UI.Page

Private _wpManager As WebPartManager

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

End Sub

Private Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
' original code
' Page.InitComplete += New EventHandler(InitializationComplete)
' VB version below:
AddHandler Page.InitComplete, New EventHandler(AddressOf
InitializationComplete)
End Sub

Public Sub InitializationComplete(ByVal sender As Object, ByVal e As
System.EventArgs)
_wpManager = WebPartManager.GetCurrentWebPartManager(Page)
Dim browseModeName As String
Dim mode As WebPartDisplayMode
Dim i As Integer

browseModeName = WebPartManager.BrowseDisplayMode.Name

Dim nModes As Integer = _wpManager.SupportedDisplayModes.Count
For i = 0 To nModes - 1
mode = _wpManager.SupportedDisplayModes.Item(i)
Dim modeName As String
modeName = mode.Name
' Make sure a mode is enabled before adding it.
If (mode.IsEnabled(_wpManager)) Then
Dim item As ListItem = New ListItem(modeName, modeName)
Me.DropDownListDisplayModes.Items.Add(item)
End If

Next i
End Sub

Protected Sub DropDownListDisplayModes_SelectedIndexChanged(ByVal sender
As Object, ByVal e As System.EventArgs) Handles
DropDownListDisplayModes.SelectedIndexChanged
Dim selectedMode As String
selectedMode = DropDownListDisplayModes.SelectedValue

Dim mode As WebPartDisplayMode
mode = _wpManager.SupportedDisplayModes([selectedMode])

If (Not (mode Is Nothing)) Then
_wpManager.DisplayMode = mode
End If
End Sub

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs)
Dim items As ListItemCollection
items = Me.DropDownListDisplayModes.Items

Dim selectedIndex As Integer

selectedIndex =
items.IndexOf(items.FindByText(_wpManager.DisplayMode.Name))
DropDownListDisplayModes.SelectedIndex = selectedIndex
End Sub

End Class


That's it... but for some reason, the 'design' option does NOT appear in the
drop down. Ideas?

For clarification, the book I'm working with is ASP.NET 2.0 Step by Step by
George Shepherd... ISBN 0-7356-2201-9 : and no, there isn't anything
regarding this issue in the errata stuff...
 
R

RhondaT

Please see my post immediately preceeding yours... as I did post the code
(as an afterthought - sorry)
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top