Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

how to make asp.net customcontrol support autorefresh

I want to make control to show numeric value and its alarm status (Hi or Lo alarm). To make it simple, i derived my class from NumericEdit.

 

I make an object from that derived class and register it to autorefresh. At this point, the value updated.

Than I override RenderControl method with my own code. At this point, the value fail to update.

 

Any idea how to resolve this?

0 Kudos
Message 1 of 8
(6,046 Views)

Hi taov,

 

Can you give us more detail on why you are using your own code for RenderControl and what you are doing differently? It sounds like you were getting the behavior you need before doing that, and there's now a bug in your method.

 

Thanks,

KyleP
Applications Engineer
National Instruments
0 Kudos
Message 2 of 8
(6,037 Views)

Hi KyleP, thanks for the reply.

 

Actually, I want to make a numeric control with alarm hi and lo indicator. The base NumericEdit control only render a textbox with numeric value inside. I want to add two boolean control (i.e. LED control) to display its alarm status. I also want to add engineering unit after its numeric value. That's why I override RenderControl.

 

 

0 Kudos
Message 3 of 8
(6,033 Views)

Can you show a little bit more of what you're doing? It would be helpful to see the code for your RenderControl method. 

 

Cheers,

KyleP
Applications Engineer
National Instruments
0 Kudos
Message 4 of 8
(6,015 Views)

Hi Kyle, sorry for late reply.

Here is my RenderControl code. 

Could you tell which part is wrong? Or is there any way to make my control support AutoRefresh

        protected override void RenderControl(System.Web.UI.HtmlTextWriter writer)
        {
            if (AlarmHiEnable)
            {
                ///Create Hi Alarm Indicator
                writer.AddStyleAttribute(HtmlTextWriterStyle.MarginBottom, "2px");
                writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0px");
                writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0px");
                writer.RenderBeginTag(HtmlTextWriterTag.Table);
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "23px");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "8px");
                writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "center");
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, this.Font.Name);
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, this.Font.Size.ToString());
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "../../images/uji12.png");
                if (AlarmHiStatus)
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, this.ColorToHex(AlarmHiEnabledColor));
                else
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, this.ColorToHex(AlarmHiDisabledColor));
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write("H");
                writer.RenderEndTag();
                writer.RenderEndTag();
                writer.RenderEndTag();
            }

 
            ///Create table as numeric indicator with caption and engineering unit container
            writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "../../images/CustomIndicatorBackground.png");
            writer.AddStyleAttribute("background-size", "100% 100%");
            writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, this.Font.Name);
            writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, this.Font.Size.ToString());
            writer.AddAttribute(HtmlTextWriterAttribute.Width, this.Width.ToString());
            writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "5px");
            writer.RenderBeginTag(HtmlTextWriterTag.Table);

            ///create caption
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
            writer.AddStyleAttribute(HtmlTextWriterStyle.Color, ColorToHex(LabelColor));
            writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, LabelTextAlign);
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.Write(Label);
            writer.RenderEndTag();
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.RenderEndTag();
            writer.RenderEndTag();
            
            ///create numeric indicator value
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "#cccccc");
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderColor, "black");
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "solid");
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "1px");
            writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "right");
            writer.AddStyleAttribute(HtmlTextWriterStyle.PaddingRight, "5px");
            writer.AddStyleAttribute(HtmlTextWriterStyle.MarginLeft, "5px");
            writer.AddStyleAttribute(HtmlTextWriterStyle.Color, ColorToHex(ValueTextColor));
            writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "50px");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.Write(Value);
            writer.RenderEndTag();
            writer.RenderEndTag();

            ///create engineering unit
            writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "white");
            writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, "Arial");
            writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, this.Font.Size.ToString());
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.Write(EngUnit);
            writer.RenderEndTag();
            writer.RenderEndTag();
            writer.RenderEndTag();

            if (AlarmLoEnable)
            {
                ///create Lo Alarm Indicator
                writer.AddStyleAttribute(HtmlTextWriterStyle.MarginTop, "2px");
                writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0px");
                writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0px");
                writer.RenderBeginTag(HtmlTextWriterTag.Table);
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "23px");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "8px");
                writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "center");
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, this.Font.Name);
                writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, this.Font.Size.ToString());
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "../../images/uji12.png");
                if (AlarmLoStatus)
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, this.ColorToHex(AlarmLoEnabledColor));
                else
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, this.ColorToHex(AlarmLoDisabledColor));
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write("L");
                writer.RenderEndTag();
                writer.RenderEndTag();
                writer.RenderEndTag();
            }
        }

 

0 Kudos
Message 5 of 8
(6,007 Views)

taov,
In order to add AutoRefresh event support for non-Measurement Studio ASP.NET controls, it is necessary to define the IRefreshCallbackEventHandler Interface on that control.

 

This includes a RaiseRefreshCallbackEvent method that returns a RefreshCallbackResult that specifies the updates that are to be made on the client. It also defines an ID property that must return the ID of the server control.

 

More information can be found by opening the Measurement Studio Help and searching IRefreshCallbackEventHandler. The fourth result should be the Help Topic for IRefreshCallbackEventHandler Interface, which goes into more detail about the prototypes and namespaces for these methods.

Jared A.
Applications Engineer
National Instruments
0 Kudos
Message 6 of 8
(6,000 Views)

Jared,

Thanks for the answer. I have implement IRefreshCallbackEventHandler in my custom control and that solved the problem. The value able to refresh.

 

But the second problem is, it only able to refresh the value property. I need the alarm status property also refreshed.

 

Does IRefreshCallbackEventHandler support multiple ID in single control?

0 Kudos
Message 7 of 8
(5,989 Views)

Hey taov,

 

Could you give us some code on how you're implementing the IRefreshCallbackEventHandler?

 

Cheers,

KyleP
Applications Engineer
National Instruments
0 Kudos
Message 8 of 8
(5,977 Views)