Showing posts with label write. Show all posts
Showing posts with label write. 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 checking atlas update progress

Hi,

I was wondering if there's a way to check the status of atlas update panel through script? I want to write some scripts after the update panel complete its process of getting data from the server.

Thanks.

hello.

well, you can do that easilly by handling the propertychanged event of the _pagerequestmanager object. search this forum for _pageRequestManager and _inPostBack. you'll find 1 or 2 posts on how to do that (from xml-script and javascript).


Thanks Luis. I found my answer in one of the posts.

Monday, March 26, 2012

Programmatically trigger modal popup

I want to write a page that checks for a cookie via Javascript and then possibly opens a modal dialog box. How do I trigger the modal popup via client side javascript?

I saw the example that comes on the modal dialog that sample page, however that works with a client side event such as a click. Can I do it without listening for an event?

Hi theregit,

In the javascript where you check the cookie, you can trigger a button.

That button's click event can then be another javascript that opens a modal window.

Trigger the button like:
var myButton = document.getElementById('myButton');
myButton.click();

Is this an answer to your question?
if you have comments/remarks/questions .. please do so!

Kind regards
Wim


Try this ,

Show and Hide ModalPopupExtender from JavaScript

Hope this helps


Phanatic,

Thank you sooo much for that post. I was having the problem with the 'null' is null or not an object error. Once I used the pageLoad() method it worked great.