473,657 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP 2.0 Webpart Connections

I am having some trouble with my webpart connections on postbacks.

I basically have two webparts in the same zone, 1 provider and 1 consumer.
The provider has a dropdown list and submit button and the consumer has a
text box that displays data depending on what is selected in the provider.
On the initial page hit, The consumer connection is established before the
CreateChildCont rols event (which is fine), but on the postback, the
CreateChildCont rols event occurs before the consumer connection is
established, so the the CreateChildCont rols method does not know which value
was selected in the provider at this time.

Does anyone else have this problem or know the correct way to do this?

I've noticed that the CreateChildCont rols only gets fired before the
connection gets established when there are any input (text, checkbox, etc)
controls on the form. If you run the code below, you'll notice the consumer
is only rendered every other postback because when the connection isn't set,
the consumer can't render the control because it doesn't know which type to
display. And when the consumer has no input controls, on the next postback,
the connection is established first and the controls get rendered.

I've come up with a workaround, but I'd like a cleaner solution. My
workaround is to just call CreateChildCont rols again in the Consumer
connection code (You'll see it commented out in the code below). This will
ensure that the controls are created again after the connection has been
made. I don't like this because 1) On the initial page hit the controls we
be rendered and then deleted and re-rendered when the connection is made
which is inefficient.

I guess some other questions would be...

1. I know the CreateChildCont rols event is called at different times
depending on page circumstances, but does anyone know those circumstances?

2. Is there a way to make sure that the connection happens before the
CreateChildCont rols? Or a way to force the connection at some point in the
page life cycle?
Any help with this would be greatly appreciated... I've been banging my head
against this one for a couple days now.

Thanks!!!

Code follows...

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
Inherits="_Defa ult" EnableViewState ="false"%>
<%@ Register TagPrefix="aspS ample" Namespace="Samp les.AspNet.CS.C ontrols" %>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:WebPartMan ager ID="mgr" runat="server">
<StaticConnecti ons>
<asp:WebPartCon nection ID="conn1"
ConsumerConnect ionPointID="MyC onsumer"
ConsumerID="con sumer1"
ProviderConnect ionPointID="MyP rovider"
ProviderID="pro vider1" />
</StaticConnectio ns>
</asp:WebPartMana ger>

<asp:WebPartZon e ID="WebPartZone 1" runat="server">
<ZoneTemplate >
<aspSample:ZipC odeWebPart ID="provider1" runat="server" Title="My
Provider" />
<aspSample:Weat herWebPart ID="consumer1" runat="server" Title="My
Consumer" />
</ZoneTemplate>
</asp:WebPartZone >

<asp:Connection sZone ID="Connections Zone1" runat="server">
</asp:Connections Zone>
</form>
</body>
</html>


namespace Samples.AspNet. CS.Controls
{
using System;
using System.Web;
using System.Web.Secu rity;
using System.Security .Permissions;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;

public interface IMyConnection
{
string MySelection { get; }
}

public class ZipCodeWebPart : WebPart, IMyConnection
{
private string _mySelection = String.Empty;
private DropDownList _dll;

public ZipCodeWebPart( )
{
}

public virtual string MySelection
{
get { return _mySelection; }
}

[ConnectionProvi der("Zip Code Provider", "MyProvider ")]
public IMyConnection ProvideMyProvid er()
{
return this;
}

protected override void CreateChildCont rols()
{
Controls.Clear( );

_dll = new DropDownList();

_dll.Items.Add( "One");
_dll.Items.Add( "Two");
_dll.Items.Add( "Three");
_dll.CausesVali dation = true;
this.Controls.A dd(_dll);

Button myButton = new Button();
myButton.Text = "Display";
myButton.Click +=new EventHandler(my Button_Click);
this.Controls.A dd(myButton);
}

void myButton_Click( object sender, EventArgs e)
{
_mySelection = _dll.SelectedVa lue;
}

}

public class WeatherWebPart : WebPart
{
private IMyConnection _provider;

[ConnectionConsu mer("Zip Code Consumer", "MyConsumer ")]
public void GetMyProvider(I MyConnection Provider)
{
_provider = Provider;
}

protected override void OnPreRender(Eve ntArgs e)
{
EnsureChildCont rols();

}

protected override void CreateChildCont rols()
{

if (this._provider != null)
{
Controls.Clear( );

TextBox tb = new TextBox();
tb.ID = "myTextBox" ;
this.Controls.A dd(tb);

switch (_provider.MySe lection)
{
case "One":
tb.Text = "Display One Data";
break;
case "Two":
tb.Text = "Display Two Data";
break;
case "Three":
tb.Text = "Display Three Data";
break;
}
}
}
}
}
Nov 20 '05 #1
0 1494

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

Similar topics

0
1201
by: J. Jespersen | last post by:
Hi people, I fiddling with webparts, and have created my own custom webpart from scratch. The webpart itself is contained in a myPart.dll I have two different sites. SiteA and SiteB. Both are webparts-based. I have added the webpart to my toolbox, and added it to a declarativeCatalogPart, and finally added the webpart to a webPartZone. No problemo. I have allowed the webpart for export, and have exported it to a
3
4737
by: DexHex | last post by:
Hi, I am stumpt. Is there anyway to set the background image on a webpart title?
0
4342
by: tony dong | last post by:
Hi there I use vs.net 2005 with standard sql 2005 under machine\sql2005 for instant when I create webpart, the code get from quickstart as follow: <%@ Page Language="C#" %> <%@ Register Src="WebPartPageMenu.ascx" TagName="WebPartPageMenu" TagPrefix="uc1" %> <html> <head id="Head1" runat="server"> <title>Web Part Page</title>
0
1077
by: arthernan | last post by:
If I separate the code into two buttons on a web page it works. One button creates the webpart and the second creates the connection. But the minute I move the connection creation code to the web part creation, I get a webpart does not belong to this page. I can appreciate how the webparts may not be ready for the connections. How do I make them ready on the same event? I don't want to have users clicking two buttons to open two...
3
1726
by: Jav | last post by:
I create a UserControl (.ascx), and then change it in code to: Inherits System.Web.UI.WebControls.WebParts.WebPart expecting that it will now be treated as a WebPart. But this immediately generates 2 errors. How does one go about creating a WebPart by inheriting as above? (I know that I can drag a UserControl into a WebPartZone and it will be wrapped in a GenericWebPart.) Thanks Jav
2
1354
by: MrCrool | last post by:
Hi I am trying to develop WebParts that will interact with each other to make up a highly customizable "system", but I am having trouble with the order in which the webparts connect and communicate. If you have a WebPart that is both consumer and provider it is most likely the "middle" component in your communication: It receives a value from it's provider, uses this value for some purpose, and sends it's own value on to the consumer...
0
1107
by: rote | last post by:
I'm trying to use jan's wonderful SmartPart from http://weblogs.asp.net/jan/archive/2007/02.aspx After trying the Connections Demo from the site and making a connectable webpart When using the UpdatePanel i get the error Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters,...
1
4747
by: archu007 | last post by:
Hi frds i hav used webparts in my application and i'm using sqlserver2000 when i run the application the following error is displayed "An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance...
4
1545
by: Arnab das | last post by:
I am working in asp.net webpart.I want to show the delete warning message in a modal popup. How can I achieve this?
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4151
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1611
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.