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

Passing data to usercontrol (URGENT)

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Anonymous:
Check out: http://openmymind.net/communication/index.html for a detailed
explanation of how to best get a page and its user controls to chat...but,
my guess is that you have somethin glike:

dim control as Control = Page.LoadControl("someThing.ascx")
SomePlaceHolder.Controls.Add(control)

if you have a public property that you want to set, you must cast the
control to the actual class someThing.ascx is, for example:

dim control as SomeThing = Ctype(Page.LoadControl("someThing.ascx"))
control.SomeValue = xxx 'this will work now
SomePlaceHodler.Controls.Add(control)
this assumes that your user control looks a bit like:

public class SomeThing
inherits UserControl

public property SomeValue() as String
get ... end get
set ... end set

...
end class

Hope this helps,
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Anonymous" <an*******@discussions.microsoft.com> wrote in message
news:21****************************@phx.gbl...
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

Nov 19 '05 #2

P: n/a
Ok, that works so far. But here is the real problem. I
have a datagrid. In the datagrid I load a user control
which contains another datagrid. Its like a nested grid.
When the user presses the + button then it collapses the
content and loads the usercontrol. BUT if he then presses
the + of the second row, then the first row (which was
expanded/open) closes automatically. BUT I want that row
to stay open, until I press the - sign. This is really
URGENT.

-----Original Message-----
Anonymous:
Check out: http://openmymind.net/communication/index.html for a detailedexplanation of how to best get a page and its user controls to chat...but,my guess is that you have somethin glike:

dim control as Control = Page.LoadControl ("someThing.ascx")SomePlaceHolder.Controls.Add(control)

if you have a public property that you want to set, you must cast thecontrol to the actual class someThing.ascx is, for example:
dim control as SomeThing = Ctype(Page.LoadControl ("someThing.ascx"))control.SomeValue = xxx 'this will work now
SomePlaceHodler.Controls.Add(control)
this assumes that your user control looks a bit like:

public class SomeThing
inherits UserControl

public property SomeValue() as String
get ... end get
set ... end set

...
end class

Hope this helps,
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Anonymous" <an*******@discussions.microsoft.com> wrote in messagenews:21****************************@phx.gbl...
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

.

Nov 19 '05 #3

P: n/a
Ahh..the full question.

This is certainly doable, but I'd recommend you look at the wonderful (and
wonderfully free) control by Denis Bauer called HierarGrid, which you can
download (and demo) at :
http://www.denisbauer.com/ASPNETCont...ierarGrid.aspx

You can also get the source code which should show you how he did it...
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Anonymous" <an*******@discussions.microsoft.com> wrote in message
news:0c****************************@phx.gbl...
Ok, that works so far. But here is the real problem. I
have a datagrid. In the datagrid I load a user control
which contains another datagrid. Its like a nested grid.
When the user presses the + button then it collapses the
content and loads the usercontrol. BUT if he then presses
the + of the second row, then the first row (which was
expanded/open) closes automatically. BUT I want that row
to stay open, until I press the - sign. This is really
URGENT.

-----Original Message-----
Anonymous:
Check out: http://openmymind.net/communication/index.html

for a detailed
explanation of how to best get a page and its user

controls to chat...but,
my guess is that you have somethin glike:

dim control as Control = Page.LoadControl

("someThing.ascx")
SomePlaceHolder.Controls.Add(control)

if you have a public property that you want to set, you

must cast the
control to the actual class someThing.ascx is, for

example:

dim control as SomeThing = Ctype(Page.LoadControl

("someThing.ascx"))
control.SomeValue = xxx 'this will work now
SomePlaceHodler.Controls.Add(control)
this assumes that your user control looks a bit like:

public class SomeThing
inherits UserControl

public property SomeValue() as String
get ... end get
set ... end set

...
end class

Hope this helps,
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Anonymous" <an*******@discussions.microsoft.com> wrote

in message
news:21****************************@phx.gbl...
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

.

Nov 19 '05 #4

P: n/a
Roy
Anonymous... I would love you forever if you would post your code. :)
I'm working on something similar.

Nov 19 '05 #5

P: n/a
I already did that and I would like to stick with my
approach. I have already invested some time in his control
and it doesnt work for me. Please advise.

-----Original Message-----
Ahh..the full question.

This is certainly doable, but I'd recommend you look at the wonderful (andwonderfully free) control by Denis Bauer called HierarGrid, which you candownload (and demo) at :
http://www.denisbauer.com/ASPNETCont...ierarGrid.aspx

You can also get the source code which should show you how he did it...Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Anonymous" <an*******@discussions.microsoft.com> wrote in messagenews:0c****************************@phx.gbl...
Ok, that works so far. But here is the real problem. I
have a datagrid. In the datagrid I load a user control
which contains another datagrid. Its like a nested grid.
When the user presses the + button then it collapses the
content and loads the usercontrol. BUT if he then presses the + of the second row, then the first row (which was
expanded/open) closes automatically. BUT I want that row
to stay open, until I press the - sign. This is really
URGENT.

>-----Original Message-----
>Anonymous:
>Check out:
http://openmymind.net/communication/index.html for a detailed
>explanation of how to best get a page and its user

controls to chat...but,
>my guess is that you have somethin glike:
>
>dim control as Control = Page.LoadControl

("someThing.ascx")
>SomePlaceHolder.Controls.Add(control)
>
>if you have a public property that you want to set, you

must cast the
>control to the actual class someThing.ascx is, for

example:
>
>dim control as SomeThing = Ctype(Page.LoadControl

("someThing.ascx"))
>control.SomeValue = xxx 'this will work now
>SomePlaceHodler.Controls.Add(control)
>
>
>this assumes that your user control looks a bit like:
>
>public class SomeThing
> inherits UserControl
>
> public property SomeValue() as String
> get ... end get
> set ... end set
>
> ...
>end class
>
>Hope this helps,
>Karl
>
>
>--
>MY ASP.Net tutorials
>http://www.openmymind.net/
>
>
>"Anonymous" <an*******@discussions.microsoft.com> wrote

in message
>news:21****************************@phx.gbl...
>> 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
>
>
>.
>

.

Nov 19 '05 #6

P: n/a
Roy
Or, if you're concerned because of copywrite purposes... ;P ...please
check out my post: Simple UserControl Question: why won't this work?
I suspect a small nudge from you could answer my question. :)

Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.