Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Newbie: Custom Server Controls and Codebehind

Reply
Thread Tools

Newbie: Custom Server Controls and Codebehind

 
 
Wardeaux
Guest
Posts: n/a
 
      01-15-2004
Help! I'm developing a custom server control and want to get/set properties
in my codebehind. I have the control set within the HTML page correctly and
it loads/displays correctly, but when I try to compile my aspx.vb code, it
complains that my variable name is undeclared. Is there a good article or
sample I can use to master this? I don't need Postback, but I do want the
properties avail during other controls postbacks. ANY assist is most
appreciated!
wardeaux


 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      01-15-2004
The web is stateless, so if you wanted properties to persist your going to
have to save it into viewstate, or a session variable. Viewstate is your
best bet coz it will save the values into the page and then retrieve them
after postback. This is how webserver controls maintain state.
In a get/set accessors scenario the following is correct. If you are unable
to compile and it says a variable is not declared this has nothing to do
with your values not being persisted but that you are using an undeclared
variable. So declare the variable before using it ;P In the following
example I have text declared as string --this is how you need to do it ;P
get/set accessors are useful if you wanted to pass values to another
page --plus there are some extra steps you need to take in the receiving
page etc
Look in the docs, its explained in detail.

Public Property Text() As String
Get
Return CType(ViewState("Text"), String)
End Get
Set
ViewState("Text") = value
End Set
End Property
"Wardeaux" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Help! I'm developing a custom server control and want to get/set

properties
> in my codebehind. I have the control set within the HTML page correctly

and
> it loads/displays correctly, but when I try to compile my aspx.vb code, it
> complains that my variable name is undeclared. Is there a good article or
> sample I can use to master this? I don't need Postback, but I do want the
> properties avail during other controls postbacks. ANY assist is most
> appreciated!
> wardeaux
>
>



 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      01-15-2004
oops, custom server control. My mistake. The example i just showed you is
good. I though you were using the get/set accessors in your page and that
didnt make much sense to me ;P
Please ignore where i said "get/set accessors are useful if you wanted to
pass values to another page --plus there are some extra steps you need to
take in the receiving page etc Look in the docs, its explained in detail"

Look at the link for more details on how to maintain state in your web
custom control
http://msdn.microsoft.com/library/de...eincontrol.asp

"Wardeaux" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Help! I'm developing a custom server control and want to get/set

properties
> in my codebehind. I have the control set within the HTML page correctly

and
> it loads/displays correctly, but when I try to compile my aspx.vb code, it
> complains that my variable name is undeclared. Is there a good article or
> sample I can use to master this? I don't need Postback, but I do want the
> properties avail during other controls postbacks. ANY assist is most
> appreciated!
> wardeaux
>
>



 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      01-15-2004
Re-reading my post, ignore this too : "If you are unable to compile and it
says a variable is not declared this has nothing to do with your values not
being persisted but that you are using an undeclared variable. So declare
the variable before using it ;P"


"Alessandro Zifiglio" <(E-Mail Removed)> wrote in
message news:W_BNb.3605$(E-Mail Removed)...
> oops, custom server control. My mistake. The example i just showed you is
> good. I though you were using the get/set accessors in your page and that
> didnt make much sense to me ;P
> Please ignore where i said "get/set accessors are useful if you wanted to
> pass values to another page --plus there are some extra steps you need to
> take in the receiving page etc Look in the docs, its explained in detail"
>
> Look at the link for more details on how to maintain state in your web
> custom control
>

http://msdn.microsoft.com/library/de...eincontrol.asp
>
> "Wardeaux" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Help! I'm developing a custom server control and want to get/set

> properties
> > in my codebehind. I have the control set within the HTML page correctly

> and
> > it loads/displays correctly, but when I try to compile my aspx.vb code,

it
> > complains that my variable name is undeclared. Is there a good article

or
> > sample I can use to master this? I don't need Postback, but I do want

the
> > properties avail during other controls postbacks. ANY assist is most
> > appreciated!
> > wardeaux
> >
> >

>
>



 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      01-15-2004
aaaZZzz .. . .Ignore this too : "or a session variable"
"Alessandro Zifiglio" <(E-Mail Removed)> wrote in
message news:50CNb.3606$(E-Mail Removed)...
> Re-reading my post, ignore this too : "If you are unable to compile and it
> says a variable is not declared this has nothing to do with your values

not
> being persisted but that you are using an undeclared variable. So declare
> the variable before using it ;P"
>
>
> "Alessandro Zifiglio" <(E-Mail Removed)> wrote in
> message news:W_BNb.3605$(E-Mail Removed)...
> > oops, custom server control. My mistake. The example i just showed you

is
> > good. I though you were using the get/set accessors in your page and

that
> > didnt make much sense to me ;P
> > Please ignore where i said "get/set accessors are useful if you wanted

to
> > pass values to another page --plus there are some extra steps you need

to
> > take in the receiving page etc Look in the docs, its explained in

detail"
> >
> > Look at the link for more details on how to maintain state in your web
> > custom control
> >

>

http://msdn.microsoft.com/library/de...eincontrol.asp
> >
> > "Wardeaux" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Help! I'm developing a custom server control and want to get/set

> > properties
> > > in my codebehind. I have the control set within the HTML page

correctly
> > and
> > > it loads/displays correctly, but when I try to compile my aspx.vb

code,
> it
> > > complains that my variable name is undeclared. Is there a good

article
> or
> > > sample I can use to master this? I don't need Postback, but I do want

> the
> > > properties avail during other controls postbacks. ANY assist is most
> > > appreciated!
> > > wardeaux
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Wardeaux
Guest
Posts: n/a
 
      01-19-2004
I appreciate your replies, but I think you missed my question...
I have a custom control. I want to set properties and get values from my
custom control in my Codebehind. I place the control on my HTML page
(MyPage.aspx). I name the control MyControl1. Now I go the codebehind
MyPage.aspx.vb and in the PageLoad sub I want to load MyControl1 with data,
but when I type:
"...
MyControl1.MyProperty = "Hello world!"
...."
I get a compile-time error stating that MyControl1 is an undeclared
variable...
How can I get a handle to the custom control object so that I can use it in
MyPage.aspx.vb?
thanks in advance!
wardeaux

"Alessandro Zifiglio" <(E-Mail Removed)> wrote in
message news:W_BNb.3605$(E-Mail Removed)...
> oops, custom server control. My mistake. The example i just showed you is
> good. I though you were using the get/set accessors in your page and that
> didnt make much sense to me ;P
> Please ignore where i said "get/set accessors are useful if you wanted to
> pass values to another page --plus there are some extra steps you need to
> take in the receiving page etc Look in the docs, its explained in detail"
>
> Look at the link for more details on how to maintain state in your web
> custom control
>

http://msdn.microsoft.com/library/de...eincontrol.asp
>
> "Wardeaux" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Help! I'm developing a custom server control and want to get/set

> properties
> > in my codebehind. I have the control set within the HTML page correctly

> and
> > it loads/displays correctly, but when I try to compile my aspx.vb code,

it
> > complains that my variable name is undeclared. Is there a good article

or
> > sample I can use to master this? I don't need Postback, but I do want

the
> > properties avail during other controls postbacks. ANY assist is most
> > appreciated!
> > wardeaux
> >
> >

>
>



 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      01-19-2004
Wardeaux,
Just like any webControl. If you had coded it correctly as you drag it onto
your webform, you should get the declaration for your webcontrol in your
code behind just like with any webcontrol, use that to access its
properties.

Another way is to load it dynamically, you do this like any webcontrol
again. You declare the type first

dim mycontrol1 as mycontrol = new mycontrol
'then add the control to the page, or placeholder control
placeholder1.controls.add(mycontrol1)
'then set any properties --now it will maintain state
mycontrol1.myproperty = "Hello world"

You probably know this, however make sure you have added a reference to your
customcontrol and you see it in your references node in solution
explorer --if you added your custom control your toolbox and dragged and
dropped it onto your page then the reference is already added --otherwise
add the reference

"Wardeaux" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I appreciate your replies, but I think you missed my question...
> I have a custom control. I want to set properties and get values from my
> custom control in my Codebehind. I place the control on my HTML page
> (MyPage.aspx). I name the control MyControl1. Now I go the codebehind
> MyPage.aspx.vb and in the PageLoad sub I want to load MyControl1 with

data,
> but when I type:
> "...
> MyControl1.MyProperty = "Hello world!"
> ..."
> I get a compile-time error stating that MyControl1 is an undeclared
> variable...
> How can I get a handle to the custom control object so that I can use it

in
> MyPage.aspx.vb?
> thanks in advance!
> wardeaux
>
> "Alessandro Zifiglio" <(E-Mail Removed)> wrote in
> message news:W_BNb.3605$(E-Mail Removed)...
> > oops, custom server control. My mistake. The example i just showed you

is
> > good. I though you were using the get/set accessors in your page and

that
> > didnt make much sense to me ;P
> > Please ignore where i said "get/set accessors are useful if you wanted

to
> > pass values to another page --plus there are some extra steps you need

to
> > take in the receiving page etc Look in the docs, its explained in

detail"
> >
> > Look at the link for more details on how to maintain state in your web
> > custom control
> >

>

http://msdn.microsoft.com/library/de...eincontrol.asp
> >
> > "Wardeaux" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Help! I'm developing a custom server control and want to get/set

> > properties
> > > in my codebehind. I have the control set within the HTML page

correctly
> > and
> > > it loads/displays correctly, but when I try to compile my aspx.vb

code,
> it
> > > complains that my variable name is undeclared. Is there a good

article
> or
> > > sample I can use to master this? I don't need Postback, but I do want

> the
> > > properties avail during other controls postbacks. ANY assist is most
> > > appreciated!
> > > wardeaux
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Wardeaux
Guest
Posts: n/a
 
      01-19-2004
Thanks for the reply! I added the control MANUALLY to the aspx page (coded
by hand the @reference and the <Prefix:Tagname> tags... that's probably why
the correct references weren't added to the aspx.vb file... thanks!

"Alessandro Zifiglio" <(E-Mail Removed)> wrote in
message news:Y7YOb.5324$(E-Mail Removed)...
> Wardeaux,
> Just like any webControl. If you had coded it correctly as you drag it

onto
> your webform, you should get the declaration for your webcontrol in your
> code behind just like with any webcontrol, use that to access its
> properties.
>
> Another way is to load it dynamically, you do this like any webcontrol
> again. You declare the type first
>
> dim mycontrol1 as mycontrol = new mycontrol
> 'then add the control to the page, or placeholder control
> placeholder1.controls.add(mycontrol1)
> 'then set any properties --now it will maintain state
> mycontrol1.myproperty = "Hello world"
>
> You probably know this, however make sure you have added a reference to

your
> customcontrol and you see it in your references node in solution
> explorer --if you added your custom control your toolbox and dragged and
> dropped it onto your page then the reference is already added --otherwise
> add the reference
>
> "Wardeaux" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > I appreciate your replies, but I think you missed my question...
> > I have a custom control. I want to set properties and get values from

my
> > custom control in my Codebehind. I place the control on my HTML page
> > (MyPage.aspx). I name the control MyControl1. Now I go the codebehind
> > MyPage.aspx.vb and in the PageLoad sub I want to load MyControl1 with

> data,
> > but when I type:
> > "...
> > MyControl1.MyProperty = "Hello world!"
> > ..."
> > I get a compile-time error stating that MyControl1 is an undeclared
> > variable...
> > How can I get a handle to the custom control object so that I can use it

> in
> > MyPage.aspx.vb?
> > thanks in advance!
> > wardeaux
> >
> > "Alessandro Zifiglio" <(E-Mail Removed)> wrote in
> > message news:W_BNb.3605$(E-Mail Removed)...
> > > oops, custom server control. My mistake. The example i just showed you

> is
> > > good. I though you were using the get/set accessors in your page and

> that
> > > didnt make much sense to me ;P
> > > Please ignore where i said "get/set accessors are useful if you

wanted
> to
> > > pass values to another page --plus there are some extra steps you need

> to
> > > take in the receiving page etc Look in the docs, its explained in

> detail"
> > >
> > > Look at the link for more details on how to maintain state in your web
> > > custom control
> > >

> >

>

http://msdn.microsoft.com/library/de...eincontrol.asp
> > >
> > > "Wardeaux" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > Help! I'm developing a custom server control and want to get/set
> > > properties
> > > > in my codebehind. I have the control set within the HTML page

> correctly
> > > and
> > > > it loads/displays correctly, but when I try to compile my aspx.vb

> code,
> > it
> > > > complains that my variable name is undeclared. Is there a good

> article
> > or
> > > > sample I can use to master this? I don't need Postback, but I do

want
> > the
> > > > properties avail during other controls postbacks. ANY assist is

most
> > > > appreciated!
> > > > wardeaux
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      01-19-2004
Your welcome. Glad i could help
"Wardeaux" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks for the reply! I added the control MANUALLY to the aspx page

(coded
> by hand the @reference and the <Prefix:Tagname> tags... that's probably

why
> the correct references weren't added to the aspx.vb file... thanks!
>
> "Alessandro Zifiglio" <(E-Mail Removed)> wrote in
> message news:Y7YOb.5324$(E-Mail Removed)...
> > Wardeaux,
> > Just like any webControl. If you had coded it correctly as you drag it

> onto
> > your webform, you should get the declaration for your webcontrol in your
> > code behind just like with any webcontrol, use that to access its
> > properties.
> >
> > Another way is to load it dynamically, you do this like any webcontrol
> > again. You declare the type first
> >
> > dim mycontrol1 as mycontrol = new mycontrol
> > 'then add the control to the page, or placeholder control
> > placeholder1.controls.add(mycontrol1)
> > 'then set any properties --now it will maintain state
> > mycontrol1.myproperty = "Hello world"
> >
> > You probably know this, however make sure you have added a reference to

> your
> > customcontrol and you see it in your references node in solution
> > explorer --if you added your custom control your toolbox and dragged and
> > dropped it onto your page then the reference is already

added --otherwise
> > add the reference
> >
> > "Wardeaux" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > I appreciate your replies, but I think you missed my question...
> > > I have a custom control. I want to set properties and get values from

> my
> > > custom control in my Codebehind. I place the control on my HTML page
> > > (MyPage.aspx). I name the control MyControl1. Now I go the codebehind
> > > MyPage.aspx.vb and in the PageLoad sub I want to load MyControl1 with

> > data,
> > > but when I type:
> > > "...
> > > MyControl1.MyProperty = "Hello world!"
> > > ..."
> > > I get a compile-time error stating that MyControl1 is an undeclared
> > > variable...
> > > How can I get a handle to the custom control object so that I can use

it
> > in
> > > MyPage.aspx.vb?
> > > thanks in advance!
> > > wardeaux
> > >
> > > "Alessandro Zifiglio" <(E-Mail Removed)> wrote

in
> > > message news:W_BNb.3605$(E-Mail Removed)...
> > > > oops, custom server control. My mistake. The example i just showed

you
> > is
> > > > good. I though you were using the get/set accessors in your page and

> > that
> > > > didnt make much sense to me ;P
> > > > Please ignore where i said "get/set accessors are useful if you

> wanted
> > to
> > > > pass values to another page --plus there are some extra steps you

need
> > to
> > > > take in the receiving page etc Look in the docs, its explained in

> > detail"
> > > >
> > > > Look at the link for more details on how to maintain state in your

web
> > > > custom control
> > > >
> > >

> >

>

http://msdn.microsoft.com/library/de...eincontrol.asp
> > > >
> > > > "Wardeaux" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > Help! I'm developing a custom server control and want to get/set
> > > > properties
> > > > > in my codebehind. I have the control set within the HTML page

> > correctly
> > > > and
> > > > > it loads/displays correctly, but when I try to compile my aspx.vb

> > code,
> > > it
> > > > > complains that my variable name is undeclared. Is there a good

> > article
> > > or
> > > > > sample I can use to master this? I don't need Postback, but I do

> want
> > > the
> > > > > properties avail during other controls postbacks. ANY assist is

> most
> > > > > appreciated!
> > > > > wardeaux
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
databound custom controls vs composite databound custom controls rodchar ASP .Net 0 11-26-2007 03:51 PM
How do I group the TextBox controls and get their values in codebehind pages? Learner ASP .Net 5 05-24-2006 01:10 PM
codebehind and custom namespce mark.irwin@myrapidsys.com ASP .Net 0 09-29-2005 09:35 PM
codebehind and custom objects Karl Hungus ASP .Net 5 02-09-2004 09:52 PM
Re: User Controls and CodeBehind Marc Hoeppner ASP .Net 1 07-17-2003 01:17 AM



Advertisments