User Control Passing Data To Another User Control?

I got two user controls in a .aspx page. one user control contains a list of names along with the user id as that listbox .value property. now when the user selects a user a clicks on a command button it needs to send the value of the selected user name to another user control in the same form name shippingInfo; Anyone know how to do this; I keep getting a "Object reference not set to an instance of an object" error message here is the code for the MyContacts control (the one with the user name and user id value) 


Imports PackageDeliveryVB.ShippingRequestInfo
Public Class MyContacts
Inherits System.Web.UI.UserControl
Dim ShippingRequestInfo As New ShippingRequestInfo
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'If the user is authenticated then query the web service for the required data

If Page.User.Identity.IsAuthenticated = True Then
Else
'Nothing for the time being.
End If
End Sub
Private Sub btnGetContact_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnGetContact.Click
ShippingRequestInfo.MyContactsUserID(Me.ddMyContacts.SelectedValue)
End Sub
End Class

and here is the code to the receiving control; for the time being all I want it to do is take the value of the incoming uid and display it on a text box, this is what's generating the error msg.

Imports System.Web.Security
Imports PackageDeliveryVB.AuthWS
Imports PackageDeliveryVB.DataWS

Public Class ShippingRequestInfo
Inherits System.Web.UI.UserControl
Dim m_AuthWS As New AuthWS.AuthService
Dim m_DataWS As New DataWS.DataService
Dim userInfo As DataSet
Dim myContacts As MyContacts
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'If the user is authenticated then call the webservice and get his account information
If Not IsPostBack Then 'Only load the user settings once.
'Make sure that they are Authenticated.
If Me.Page.User.Identity.IsAuthenticated Then
userInfo = m_AuthWS.ShippingRequestUserInfo(Page.User.Identity.Name)
With userInfo.Tables(0).Rows(0)
Me.lblFullName.Text = .Item(1)
Me.lblPhoneNumber.Text = .Item(2)
Me.lblDepartmentName.Text = .Item(3)
Me.lblDepartmentNumber.Text = .Item(4)
End With
Else
'the user is not autheticated dont load anythings but do display a message
'indicating that they first need to login.
End If
End If
End Sub
Public Sub MyContactsUserID(ByVal Uid As Integer)
Me.txtAttention.Text = Uid
End Sub
End Class

Any help is greatly appreciated.
0
modporkchop
2/27/2004 11:01:35 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

8 Replies
1429 Views

Similar Articles

[PageSpeed] 25

The owning page is going to have to help these controls hook up. Is "ShippingRequestInfo" the class for the other user control?
Jim


MS MVP ASP.NET [VC++/MFC emeritus]


Old Dog Learns New Tricks

Preferred programming language: cuneiform on clay tablets
0
JimRoss
2/27/2004 11:07:29 PM
Yes; MyContacts needs to pass the UID to MyShippingRequestInfo control. Yes that is the class for the the other user control; how would I go about doing this?
0
modporkchop
2/27/2004 11:12:20 PM
Here's what you can do:

* in the logon control, do not create an instance of the Info control, instead just expose the variable as a public property.
* Have the owning page set the value of the property to the instance of the Info control.

Jim


MS MVP ASP.NET [VC++/MFC emeritus]


Old Dog Learns New Tricks

Preferred programming language: cuneiform on clay tablets
0
JimRoss
2/27/2004 11:23:37 PM
I'm kinda lost; any code you can give?
0
modporkchop
2/27/2004 11:34:03 PM
This is gonna be quick and dirty -- it's Friday, unwind time.

In your login control, where you currently have something like: (sorry, I don't remember the class names right now)
Dim ShippingInfo As New ShippingInfoControl
Change this line to:
Public ShippingInfo As ShippingInfoControl
------------
In the owning page, make sure you have declared variables for your two user controls:
Protected idTheShippingInfo As ShippingInfoControl
Protected idTheLogin As LoginControl
Now, in PageLoad,
Me.idTheLogin.ShippingInfo = idTheShippingInfo
Now your Login control has the page's instance of the ShippingInfo control.
[sound of cork poping and wineglasses clinking from living room]
Hope this helps. I'm outahere for 24 or so.

Jim


MS MVP ASP.NET [VC++/MFC emeritus]


Old Dog Learns New Tricks

Preferred programming language: cuneiform on clay tablets
0
JimRoss
2/27/2004 11:39:15 PM
Wow, Now I got really lost. But I did attempt to make sence of it; what ever I could grasp.

on the MyContacts User Control I created a public proterty name MyContact ID here is the code to that class.

Public Class MyContacts
Inherits System.Web.UI.UserControl
Dim m_Uid As Integer = 0
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
Private Sub btnGetContact_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnGetContact.Click
MyContactID = Me.ddMyContacts.SelectedValue
End Sub
Public Property MyContactID() As Integer
Get
Return m_Uid
End Get
Set(ByVal Value As Integer)
m_Uid = Value
End Set
End Property
End Class

Now What code should go on the owning page? since it has to read the property of the MyContactID from the MyContacts user control, then pass it to the Public Sub MyContactUserID in the MyShippingRequestInfo control. Once agian thank you for your time and patience.
0
modporkchop
2/28/2004 3:14:49 PM
You did the property exactly right. To reference it on the owning page, first add a class-level menber to the page for the user control. The name of the variable should be the same as the ID of the control in the aspx code. If you're using Visual Studio, just look at how it generates variables to represent other controls on the page. The current version of VS doesn't automatically generate these variables for user controls the way it does for regular controls, you have to add them yourself. That will look something like this:
     Protected idContactsCtl As MyContacts
Now you can reference the property in the control with something like
Dim theValue As integer

theValue = idContactsCtl.MyContactID

Jim


MS MVP ASP.NET [VC++/MFC emeritus]


Old Dog Learns New Tricks

Preferred programming language: cuneiform on clay tablets
0
JimRoss
2/29/2004 2:46:37 PM
This is what I did, on the ShippingRequest.aspx page (The host to the MyContacts and MyShippingRequestInfo user controls ) I added a label on the host page to see if the value of MyContactID (Public Property On MyContacts User Control) updates once the user selection changes. I also the code you mentioned but I still get the 'Object reference not set to an instance of an object' error message. Is there any property that I should edit on the MyContacts User control that will create the instance? Thanks for you help.


Public Class ShippingRequest
Inherits System.Web.UI.Page

Protected idContactsCtl As MyContacts
Dim theValue As Integer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
theValue = Me.idContactsCtl.MyContactID
Me.Label1.Text = theValue
End Sub

End Class

0
modporkchop
3/3/2004 5:23:46 PM
Reply:

Similar Artilces:

Problem in accessing web form data in user controls when create user control dynamically
HI. I have a problem using web user control. I designed a user control named NewsForm. This user control contains some web form elements like <asp:textbox>. When I add it in an .ASPX page, all things may be true. I can know which user filles in textbox (for example and other controls) <%@ Register TagPrefix="uc1" TagName="NewsForm" Src="NewsForm.ascx" %> and <UC1:NewsForm id="newsForm" runat="server"></UC1:NewsForm> But when i create it in code behined dynamically, however user control has web form controls but their value are blank for example //aspx co...

UpdatePanel within a web user control resets data of controls outside the user control
Hello, I have a usercontrol on my page which displays a running marquee text. It makes use of an UpdatePanel (within the user control) to refresh the marquee text (within the updatepanel) at periodic intervals. For this I added a timer control and its tick event as an async postback trigger for the UpdatePanel. I have a lot of textboxes and dropdown list boxes (all with runat=server) on the page outside the above user control. These are also contained in different UpdatePanels. Problem is, when the user control does a postback to refresh the marquee text, it causes some of...

Persisting data in a web user control, which contains a list of other web user controls.
 Hi All, I have a control I've created, which can have a number of child controls - also user controls - stored as an ArrayList, which can be added wither a design time or programmatically.My problem is when I add to the list programmatically, it doesn't persist them. So if I add 3 child controls in step 1 of a wizard, with the aim that those three will be visible inside the parent in step 3, what happens is that the parent has no child controls and the item count is 0.Can anyone help? Thanks in advance.Code:Parent Control Markup: <%@ Control Language="C#" Auto...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

Web user control inside update panel replace with another web user control
 Hi there. I have a page with a menu. an and then the content. My thing is. That i have the update panel, and inside that i have a regual panel in which i add the Web User Controls i need. Which all works fine. My problem is. That i i have a submit funcion on almoast all the Web User controls. What i would like is that i inside that update panel, can dispose the original Web user Control and then add a response Web User Control. In normal language. Is there a way that i can load one web user control into antoher and then disposose the original? Thanks in advance hello. well, what ...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

Pass data from Web User Control to Web Form
I have a Web Form that contains a Web User Control. The WUC displays dynamic content. I want to change the TITLE property of the Web Form, based on the contents of the WUC. For example, if the WUC displays information about Horses, I want to change the page title to "HORSES" by passing the string to the parent Web Form. I have tried playing with parameters and such, but I can't remember how I did this in the past. PLEASE HELP!~o0 Spin-Monkey Oo~ The best way to do this is by creating a public property on your web user control and accessing that from your web form. Check ...

Pass value from one User Control to another User Control
I have tried to pass value from one user control to another user control. Because of Page Auto Postback, Contrls are load before page is loaded. So I get the value in 2nd UC after one more post back operation. I have visited many suggessions but I cant solve this. Is anyone can help me to solve this. Thank U mfhossain@gmail.com Muhmmad Fakhrul HossainEmail: mfhossain@gmail.comPhone: +88 01715 111512Web: http://www.mfhossain.info You'd have to do that through the parent probably in it's Page_Load event handler.   userControl1.publicProperty = userControl2.publicProperty;  ...

How to access a user control from another user control in a Wizard control
My page has a wizard control and each step is a user control.  I could find the value of a control in step1 user control in the wizard page but not in step2 user control.From wizard.aspx.vb – it worksDim m_title As DropDownList = CType(Me.PersonalBox1.FindControl("ddlTitle1"), DropDownList) Question:How can I find the value of a control(textbox or dropdownlist)in step1 user control from step2 user control? I want to find “PersonalBox1.FindControl("ddlTitle1")” from Step2 AddressBox1. I have tried several ways to access it but no luck. From AddressBox.ascx.vb –...

I have a web user control being used by another web user control, but the one being used will not display the labels in the resx file.
I am using DotNetNuke version 3.13 (might be 3.013) on a Window's XP machine, SP2. I have what I find to be an extremely odd situation. I have a project called TDS.Controls. This project is a web control library. Each control has its own resx file, which is located in the App_LocalResources directory. Each control inherits from Framework.UserControlBase, just like DotNetNuke's User control in DNN\Controls\User.ascx.vb. As a matter of fact, this control is doing the exact same thing I am trying to do. It is a web user control with its own resx file being used by another web user control (See ...

User control inside another user control data binding problem
Hi allmy problem that drives me crazy for already 2 days is the following...I have a page default.aspx, user control UserProfilesList.ascx, and another user control UserPic.ascx inside the first one like this (UserProfilesList.ascx) <asp:DataList ID="UserPicsDataList" RepeatColumns="5" runat="server"> <ItemTemplate> <uc1:UserPic ID="UserPicViewer" UserId='<%# Eval("ID") %>' runat="server" /> </ItemTemplate></asp:DataList>----------------------------------------------------...

(How) Can i use the form elements of a user control from another user control???
Hi, i have a user control with 4 other user controls. Actually i have 4 panels and each user control is inside a panel. Its like a 4 page form which are all connected to each other. Is it possible to have access to web controls that i have in my user controls from the main user control. In my main user control i have a submit button and a tab list. User can browse through the tabs and each tab is bound to a panel. so clicking on tab1 makes panel1 visible which holds the first user control, second tab makes second panel visible and the rest invisible and the second panel holds the ...

Unable to access user control's user control's function\property from another user control
Hi, I used to call an user control's user control function as stated below from my user control in ASP.Net 1.1 wucCompany.wucEmployee.GetEmployeeSomething() After migrating to ASP.Net 2.0, I am unable to use any properties/functions(even the public ones) of the user control's User control's from another user control.  The way I have to do is create property\function in wucCompany which calls the wucEmployee's property\function and call the wucDepartment.GetEmployeeSomething().Since I need to do this change in too many places, I can...

Updating a Label control in one user control from another user control
Hi all, I have a main page in my music store site that has 5 user controls on it with 1 always showing main content and the others being things like a shopping cart, "best sellers", genre list etc (a la amazon). From the main content control I want to be able to set some label controls in my shopping basket control but I just can't seem to work out the syntax for how to do this: Here's the code I'm using - I'm trying to go to the 4th user control on the page (my shopping basket) then find the appropraite label, cast it locally as a Label then update the value: Label _so...

Web resources about - User Control Passing Data To Another User Control? - asp.net.web-forms

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

LEVIN: We Need Obama Control!
... Mark Levin took to the airwaves Monday night to lay out exactly what’s at stake with President Obama’s executive action on gun control. Levin ...

Denmark "Temporarily" Tightens Border Controls; Trains Cancelled; Cascade of Border Controls Grows; Understanding ...
There are so many "temporary" border controls in the EU I have lost count. Fences, train checks, walls, payoffs to Turkey, pressure on Greece, ...

Should birth control pills be available without a prescription?
Oregon becomes first state to drop prescription requirement, and some experts say access needs to loosen up even more

Lenovo LINK 32 GB Lets You Control Your Phone With Your PC Using Picture-in-Picture
... device at CES 2016 that might be up your alley. The LINK 32 GB is a dongle that connects Android smartphones to PCs, allowing users to control ...

Obama: Gun-control initiatives planned
Obama said his initiatives will not prevent every mass shooting or violent crime, but they could potentially save lives.

Barack Obama's emotional evolution on gun control
CNN Barack Obama's emotional evolution on gun control CNN Washington (CNN) The Mr. Cool in the Oval Office rarely shows emotion. But on one ...

Sweden introduces border controls to halt flow of refugees
Wall Street Journal Sweden introduces border controls to halt flow of refugees CNN (CNN) — Sweden has begun carrying out identity checks on ...

Obama Set To Implement Gun Control By Executive Order This Week
Obama Set To Implement Gun Control By Executive Order This Week

Midday open thread: Legacy admissions; Sanders backs Obama on gun control action
... : Democratic presidential hopeful Sen. Bernie Sanders on Sunday offered his support for President Obama's plan to enact stricter gun control ...

Resources last updated: 1/5/2016 12:22:45 PM