Showing posts with label operate. Show all posts
Showing posts with label operate. Show all posts

Wednesday, March 28, 2012

Programmatical change Label.Text of a set of labels in an UpdatePanel

I write engineering solutions in VB. In most cases they need to operate in both metric and English units of measure so I need to update labels such as °F and °C appropriately. I have a number of labels in an UpdatePanel that need this sort of update. Some need to switch between °F and °C while others betweem feet and meters. Which type of units of measure to use is known at Page_Load so I thought I could just make the Label.IDs meaningful (use lblTemp1, lblTemp2 etc for temperature units) and then update their .Text property based on their ID and the units of measure. I am almost there but I can't seem to gain access to the Text property once I ahve found a Label's whose text I want to change.

Dim iAsInteger = 0

Dim myLabelAs Label

'controls I want to update are in and UpdatePanel...

ForEach ctrlAs ControlIn UpdatePanel1.Controls'check to nake sure it actually has controls first...
If ctrl.HasControls()Then'cycle through all controls in the UpdatePanel...
For i = 1To ctrl.Controls.Count
'if this is a Label then
IfTypeOf ctrl.Controls(i)Is LabelThen
'if the label ID contains "lblTemp this is a temperature unit and must be updatedIf ctrl.Controls(i).ID.ToString.Contains("lblTemp")Then
'HERE IS WHERE THE PROBLEM EXISTS...'can not gain access to the Text property

myLabel =

CType(ctrl, Label)
If uofm = SIUnitsThen 'metric

myLabel.Text =

"°C"Else

myLabel.Text =

"°F"EndIfEndIfEndIfNextEndIfNext

What error do you get? Can you post your ASP.NET code?

What kind of error you are facing ??

Post it here...


The error message I currently get is due to a casting error in the line.Unable to cast object of type 'System.Web.UI.Control' to type 'System.Web.UI.WebControls.Label'.

myLabel =CType(ctrl, Label)

At this point in the code I have found a control and determined that it is in fact a Label who's Text property I need to change. However there is no Text property for the crtl so I am trying to cast the ctrl as a Label.

Jim

Programmatically exit gridviews edit mode when changing tabs

Hi,

I have a gridview in a tabpanel and I would like to have it operate such that if the user puts the gridview in edit mode and then clicks to another tab, then the gridview exits edit mode. I tried this:

Protected Sub tabContPersonnelAdmin_ActiveTabChanged(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles tabContPersonnelAdmin.ActiveTabChangedgvPersonnel.EditIndex = -1gvPersonnelType.EditIndex = -1End Sub

... but that has no effect.

Any ideas, anyone?

Heck, while I'm at it, I'd also like to be able to exit the gridview's edit mode when a panel with a collapsiblepanel extender attached to it is clicked.

I appreciate anyone's help!

Hi,

By default, the ActiveTabChanged event isn't fired on the server when another tab is clicked on the client. You need to set AutoPostBack property of the TabContainer to true.

For CollasiblePanel, it doesn't have build-in support for server side event when it's expanded or collapsed, so you may need to invoke __doPostback method on the client to force a postback. And pass different arguments in it.

Hope this helps.


Thanks, Raymond!

I'll see what I can do with that info.

Regards