By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 2,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

Passing data from Usercontrol

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.