Passing data from Usercontrol

P

Peter

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
 
S

SSW

Try this...
((URNameSpace.URWebFormName)this.Parent).UrFunction();
Replace URNameSpace with the name space of WebForm
Replace URWebFormName with The web form Name in which control reside.
UrFunction is the Function name
 
P

Peter

Thank you for your help, looks like this what I need and thank very much for
supplying an example!
 
S

Steven Cheng[MSFT]

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
 
P

Peter

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!
 
S

Steven Cheng[MSFT]

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
 
S

Steven Cheng[MSFT]

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-us/cpguide/html/cpconwebformsusercontro
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,271
Latest member
BuyAtenaLabsCBD

Latest Threads

Top