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

passing argument to user control when creating it

P: n/a
Hi there!

I made own user control for displaying and editing content. In
Page_Load of this control is checked if user is authorized for editing
if so, button for editing is shown, otherwise controll works in
display only mode. I want now use this control to add new content. The
idea is that in another web form, let's call AddNewContent.aspx there
is placed MyContentControl and I want to run in Editing mode with all
fields reset to defaults. How to do this with asp.net?

Normally I would do this using constructor and passing desired option
to a object during creation, but there are two things:
1. I got strange error when I defined contructor in MyContentControl,
2. And what's more important, where I am supposed to use this
constructor? In Page_Load of AddNewContent.aspx form it is too late.

Can you help me how to customize control apperance and behaviour
during user controll creation?

Best regards
B.
Sep 16 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a

<br********@googlemail.comwrote in message
news:c8**********************************@59g2000h sb.googlegroups.com...
Hi there!

I made own user control for displaying and editing content. In
Page_Load of this control is checked if user is authorized for editing
if so, button for editing is shown, otherwise controll works in
display only mode. I want now use this control to add new content. The
idea is that in another web form, let's call AddNewContent.aspx there
is placed MyContentControl and I want to run in Editing mode with all
fields reset to defaults. How to do this with asp.net?
There are a couple of ways to play this game. Depending on your exact needs,
here they are:

1. Add a constructor that contains the properties you need to add. Then,
fire that constructor and add the control at runtime.

2. Change the binding/display at runtime by adding the behavior to the
property you are changing. You can also set properties and create a "re"
render method.
Normally I would do this using constructor and passing desired option
to a object during creation, but there are two things:
1. I got strange error when I defined contructor in MyContentControl,
What error are you getting?
2. And what's more important, where I am supposed to use this
constructor? In Page_Load of AddNewContent.aspx form it is too late.
In some cases, Page_Load is fine. In others, you have to go to Init. It
really depends on what you are doing. If you use a constructor, it does not
make sense to anchor the control to the page in the tags. This leads to less
than WYSIWYG in the UI, however.

If you add properties, you can set them in backend events, if that is your
desire. You just end up rebinding. Not as efficient, but unless you are
performing serious calculations, the extra cycles should not affect you too
much. If they do, consider a server control, where you can use it a lot more
like a windows control.
Can you help me how to customize control apperance and behaviour
during user controll creation?
The best way, ultimately, is make this a server control. It is a bit of a
pain, but if you have the user control created, it is not a huge amount of
coding to duplicate the look. Makes it far more reusable as well.

Hope this helps.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************

Sep 17 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.