473,503 Members | 6,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Anyone able to explain this webparts problem to me?

Hello,

Sorry for the long post, but I want to try and explain it clearly...

I'm using webparts for (possibly) an unusual scenario, and I'm having
problems. This could be because I'm doing something they weren't
designed for, or it could just be that I don't understand what's going
on well enough to get it to work.

The situation is that I have a page that displays products from a
database. The products can have multiple prices, say for small medium
and large, and I want the web site owner to be able to choose the order
in which the prices are displayed. This proved to be very hard, as the
reordering needs to be all client-side to avoid the site owner having to
suffer a postback for every price moved. As webparts have a built-in
function for moving them around, they seemed worth examining for this
purpose.

I thought of setting up a webpartzone in design mode, and adding a label
for each price. That would allow the site owner to move the prices
around until they were in the right order. When the page was submitted,
I would read the order of the labels and set the display order of the
prices based on that.

I tried this with hard-coded labels inside the webpartzone and it worked
fine. The problem came when I tried to add the labels in the Page_Load
event. The page showed fine, but as soon as you move a webpart, they all
disappear. I cannot work out why this is happening.

I have shown the complete code for the page below, so if anyone would be
kind enough to try it, all you need to do is copy it into a new .aspx
file and run it. When the page first loads, you see three boxes, each
representing a price. As soon as you try and move one of them, they all
disappear.

I would be very grateful if anyone could explain what is going on here.
TIA

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">

protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
WebPartDisplayMode mode = WebPartManager1.SupportedDisplayModes["Design"];
if (mode != null) {
WebPartManager1.DisplayMode = mode;
}
for (int i = 0; i < 3; i++) {
Label lblVar = new Label();
lblVar.ID = "lbl" + i.ToString();
GenericWebPart lblWebPart = WebPartManager1.CreateWebPart(lblVar);
lblWebPart.ID = "lblVar_" + i.ToString();
lblWebPart.Title = "Price number " + i.ToString();
WebPartManager1.AddWebPart(lblWebPart, ItemList, i);
}
}
}

protected void btnOK_Click(object sender, EventArgs e) {
litMsg.Text += "Count == " + ItemList.WebParts.Count.ToString();
for (int i = 0; i < ItemList.WebParts.Count; i++) {
litMsg.Text += "<br />" + i.ToString() + " - " + ItemList.WebParts[i].Controls[0].ID;
}
}

</script>

<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:WebPartZone ID="ItemList" runat="server" BorderWidth="0" CloseVerb-Enabled="False"
CloseVerb-Visible="False" DeleteVerb-Enabled="False" DeleteVerb-Visible="False" HeaderText="Prices (variations)"
MinimizeVerb-Enabled="False" MinimizeVerb-Visible="False" Padding="0">
<ZoneTemplate />
</asp:WebPartZone>
<asp:Button ID="btnOK" runat="server" OnClick="btnOK_Click" Text="OK" /><br />
<asp:Literal ID="litMsg" runat="server" />
</div>
</form>
</body>
</html>
--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 20 '05 #1
0 1407

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4028
by: fa | last post by:
Hi there, I have created an .aspx file using Asp.Net (2.0) C#, which contains two webparts. How can i pass data/parameter between these two, so that when user chooses an item from WebPart1, I can...
1
2195
by: Astera | last post by:
I seem to be having a problem using web parts after the beta 2 release. Any time I try to have the WebPartManager on any page, I get the exception listed below. I've gone through the steps listed...
1
1769
by: ryan.mclean | last post by:
Hi all, I have a strange problem and I think it may be something in my web.config . . . but I'm not sure. I have an application that uses webpart (not sharepoint), but the nifty new .net...
3
2108
by: Bart Van Hemelen | last post by:
I'm working on a project where the user of a site will receive custom content, depending on a set of parameters. The content will all be contained in UserControls (.ascx), that will be used as...
6
2632
by: brianroisentul | last post by:
Hello, I'd like to know which dll I have to reference when I use the System.Web.UI.WebControls.Webparts namespace. Thanks, Brian
3
1459
by: Q. John Chen | last post by:
I have an INTRAnet site that need to add some content management feature. And I thought that I can use the WebParts. Since this is an internal site, I use Windows authentication so the use don't...
1
1397
by: sales | last post by:
How can I turn a webpart of for all users in the default mode and on Reset personalation. I have a portal page in ASP.net and have 7 webparts displayed, I only want 6 displayed which the option to...
3
1713
by: Robert Cramer | last post by:
Just wondering if any of you actually implement portal sites using ASP.NET Web Parts, or use Web Parts outside of portal-style sites. I'm just now learning about Web Parts, and was wondering if...
3
2144
by: clintonG | last post by:
Why don't we see more WebParts being used on the web? SharePoint gets all the fun? And what are the prevailing opinions be they what they may about the use of WebParts rather than WPF when the...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.