Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Enable controls dynamically

Reply
Thread Tools

Enable controls dynamically

 
 
=?Utf-8?B?RWQgQ2hpdQ==?=
Guest
Posts: n/a
 
      05-14-2005
Hi,

Is there a way to set webform controls to visible/invisible dynamically. Say
I have a textbox cann txtFirstName, I know the following statement can set it
visible:

txtFirstName.visible = true

Here is difficult part, I am tring to set the controls visible based on the
content of DataReader or DataSet. If the datareader has a row that has an
item "txtFirstName" then txtFirstName should be visible.

Sure I can use a big select statement to do this:

select case fieldName
case "txtFirstName":
txtFirstName.visible = true
'about another 50 case statements follow
end select

But is there a better way?

TIA
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      05-14-2005
Hi,

couldn't you run Page.FindControl based on what you have in data reader (do
it when looping the results). By default set Visible = False and when
looping the datareader, if control is found then set it to visible=true

While reader.Read()

Dim ctrl As Control=Page.FindControl(reader.GetString("Control Name"))
ctrl.Visible=True

End While
reader.Close()

If it needs to work in an environment where visibility might change between
postbacks, you probably need to have controls in some sort of array or list
where you would set others (not included in the datareader so set their
visibility to false), or then just loop through all controls on the Page to
hide those others.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Ed Chiu" <> wrote in message
news:7317A5A0-A1F8-46C9-A962-...
> Hi,
>
> Is there a way to set webform controls to visible/invisible dynamically.
> Say
> I have a textbox cann txtFirstName, I know the following statement can set
> it
> visible:
>
> txtFirstName.visible = true
>
> Here is difficult part, I am tring to set the controls visible based on
> the
> content of DataReader or DataSet. If the datareader has a row that has an
> item "txtFirstName" then txtFirstName should be visible.
>
> Sure I can use a big select statement to do this:
>
> select case fieldName
> case "txtFirstName":
> txtFirstName.visible = true
> 'about another 50 case statements follow
> end select
>
> But is there a better way?
>
> TIA



 
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
Dynamically Enable/Disable Controls Inside FormView Ryan ASP .Net 3 09-21-2009 02:02 PM
Dynamically Loaded controls loading other controls =?Utf-8?B?V291dGVy?= ASP .Net 3 02-27-2006 07:25 PM
Data and controls from dynamically added controls is rmoved on Submit David Hubbard ASP .Net 2 01-17-2006 06:52 PM
How to enable people to pay me....(enable credit card payments in my web app) Patrick ASP .Net 1 11-10-2005 11:07 AM
Inserting Controls Dynamically - with Validators Also Added Dynamically Jeffrey Todd ASP .Net 1 06-02-2005 04:33 PM



Advertisments