473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Passing data from Usercontrol

I have an Usercontrol on a WebForm, on this Usercontrol is a button, I want
to save data that's residing on the WebForm when user clicks on the button
that's on the UserControl.

How do I call a method that's in the WebForm from the button_click event or
from any other event that originate in the UserControl?

Peter
--
Thanks
-------------------
cz****@wsinc.com
Nov 18 '05 #1
9 1744
You can expose properties from your User Control. At run time ...you can assign values to the same.

A detailed article on the same can be found here.
http://radio.weblogs.com/0101986/sto...ercontrols.htm

Hope this help

Avnees
MCAD, MCSD.Net
Nov 18 '05 #2
SSW
Try this...
((URNameSpace.URWebFormName)this.Parent).UrFunctio n();
Replace URNameSpace with the name space of WebForm
Replace URWebFormName with The web form Name in which control reside.
UrFunction is the Function name

"Peter" <cz****@wsinc.com> wrote in message
news:un**************@TK2MSFTNGP09.phx.gbl...
I have an Usercontrol on a WebForm, on this Usercontrol is a button, I want to save data that's residing on the WebForm when user clicks on the button
that's on the UserControl.

How do I call a method that's in the WebForm from the button_click event or from any other event that originate in the UserControl?

Peter
--
Thanks
-------------------
cz****@wsinc.com

Nov 18 '05 #3
Thank you for your help, looks like this what I need and thank very much for
supplying an example!

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:BR**************@cpmsftngxa07.phx.gbl...
Hi Peter,
Thanks for posting in the community!
From your description, you have a ASP.NET UserControl which has a button.
When the UserControl be put
in a certain ASP.NET page, you want to call a certain method or event
handler in the container page from
the Button(in the UserControl)'s click event, yes?
If there is anything I misunderstood, please feel free to let me know.

As for this question, I think you can try exposing a public eventhandler in your UserControl and then retrieve the usercontrol in its container page's
Page_Load event and set this handler member as one of the Contaner page's
handler member function. To make this clearly, I've made a sample page and
usercontrol to show the above means and I've attached the source file in
this message.

In addtion, I've viewed the web link Avneesh has provided. That also
discusses on this means, you may also have a view on it if you feel
anything unclear.

Please try out the preceding suggestion. If you have any questions, please
feel free to let me know.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #4
Hi Peter,
Thanks for your followup. I've tested the application you provided and
found that this problem is caused by that you used "OutputCache" in the
UserControl, so when the page is second time requested, the UserControl is
not in the Page's Controls Collecdtion, it is replaced by a CacheControl.
So the "Null object reference " Exception occured. You may trun on the
page's "Trace" attribute in the <@Page ..> Directive to view the Control
collection or try remove the UserControl's OutputCache directive and see
whether the problem goes away.
Please check out the above result, if you have any further questions,
please feel free to followup.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #5
Thank you very much, removing the OutputCache did the trick! As you can
tell I am very new to ASP.NET and have no clue what each attribute does, or
what to look for when there's problems - so I appreciate all the help!

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:Oa**************@cpmsftngxa07.phx.gbl...
Hi Peter,
Thanks for your followup. I've tested the application you provided and
found that this problem is caused by that you used "OutputCache" in the
UserControl, so when the page is second time requested, the UserControl is
not in the Page's Controls Collecdtion, it is replaced by a CacheControl.
So the "Null object reference " Exception occured. You may trun on the
page's "Trace" attribute in the <@Page ..> Directive to view the Control
collection or try remove the UserControl's OutputCache directive and see
whether the problem goes away.
Please check out the above result, if you have any further questions,
please feel free to followup.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #6
Hi Peter,

Thanks for your response and your compliment. I'm also very glad that my
suggestions can help you. Also, it's my pleasure to help you. Next time if
you meet any problems or have anything unclear on ASP.NET, please always
feel free to post here. We're always willing to help you.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #7
Hi,

Peter's problem is caused by the <@output cache > he used on the webform
which will make the UserControl be replaced by a LIteralControl when it is
requested again. If you haven't used any cache on the control, I think you
can refer the following weblinks:
#Web Forms User Controls
http://msdn.microsoft.com/library/en...ormsusercontro
ls.asp?frame=true

As for the attached source, I think you need to use OE client to view the
thread. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #8
Hi,

Peter's problem is caused by the <@output cache > he used on the webform
which will make the UserControl be replaced by a LIteralControl when it is
requested again. If you haven't used any cache on the control, I think you
can refer the following weblinks:
#Web Forms User Controls
http://msdn.microsoft.com/library/en...ormsusercontro
ls.asp?frame=true

As for the attached source, I think you need to use OE client to view the
thread. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #9
Hi,

Peter's problem is caused by the <@output cache > he used on the webform
which will make the UserControl be replaced by a LIteralControl when it is
requested again. If you haven't used any cache on the control, I think you
can refer the following weblinks:
#Web Forms User Controls
http://msdn.microsoft.com/library/en...ormsusercontro
ls.asp?frame=true

As for the attached source, I think you need to use OE client to view the
thread. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #10

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

Similar topics

2
by: Curtis Justus | last post by:
Hi, I currently have a control that is on a form and I want to pass that exact instance of the control to another form (a child form that appears on a button click). The control has state,...
2
by: Dave Veeneman | last post by:
Is there a simple way to pass drag-and-drop events to a child control in a UserControl? Here's an example: I have created a UserControl which contains a treeview and some text boxes. I want to...
4
by: Stijn Goris | last post by:
Hi all, I place a usercontrol (2) on another usercontrol (1). The second usercontrol has a button. Is there a way usercontrol (1) can know when the button is clicked on usercontrol (2) without...
1
by: Josh | last post by:
Hi Guys, I have been having a big problem with trying to pass parameters into a user control when the user control is dynamically loaded into a placholder. I am developing in c#. I have get...
3
by: Dan Nash | last post by:
Hi I'm new to C#, moving from ASP, and slightly confused so bear with me! Basically I've got 4 pages, each of which runs the same user control (some header information). I want to be able to...
6
by: Anonymous | last post by:
Hello, I am loading a usercontrol with the LoadControl method and need to pass some data to the property of that control. How can I do that? THanks
4
by: Tarun Mistry | last post by:
Hi, i have a page with a user control on it, the uc is a form with a submit button. On submitting, how do I make the call get picked up by the webform the user control is in? Alteratively, is...
5
by: Tarun Mistry | last post by:
Hi all, is it possible to update a usercontrol before it is rendered? In my scenario I have a Page with a usercontrol on it. When a button is clicked on the Page, I want to update the...
9
by: Chris | last post by:
Ok, so I have this sub I wrote, and I create a new instance of a UserControl: ctrlAPs tempctrl = new ctrlAPs(); Now, I would like to be able to use this sub I wrote for more than one...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.