473,512 Members | 15,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing argument to user control when creating it

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
1 1385

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5303
by: Newbie | last post by:
Hi, I am using creating a drop down menu populated by a call to a postgresql database. The drop down menu is populated correctly (or appears to be) and then upon selecting an item in the menu it...
8
3943
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer...
3
3268
by: John C | last post by:
Hi, I am a little uncertain about the concept of passing a reference to a class to another instance of a class. for instance I thought that the following was ok: Network network = Network();...
19
4066
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
39
7592
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
6
3932
by: Max | last post by:
Last time I tried to explain this on another forum it didn't go too well, so I'll try my best and if you know what I'm talking about then please tell me how to do this. I have a class, inside I...
12
2562
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
1
1516
by: Dom | last post by:
In VB I was able (I think, it's been a long time after all) to pass a Form as an argument to a procedure, and then within that procedure, to access the controls. For example, public void MyProc...
1
1178
by: Nathan Sokalski | last post by:
I have finally figured out how to create transparency in GIF files when creating them with VB.NET (it is harder than I think it should be, but at least I can do it now). I would like to write a...
0
7252
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
7153
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
7432
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...
1
7093
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
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.