Monday, March 26, 2012

UpdatePanel "kind of" Hidding DIVs

The Update pannel is kind of hidding the divs within it. I said kind of because either VMD2005ED or VS2005 "sometimes" shows errors if the div control is used in the codebehind. And even though when the errors are shown I go ahead and run it with errors and it works fine. But is very unconfortable to get this error messages everytime. I mean, in the codebehind th div has intellisense and all, but the undeclared error BC30451 still shows.

For example:

apsx file:

<atlas:UpdatePanel ID="upTest" runat="server">
<ContentTemplate>
<div id="div1" runat="server">
test
</div>
</ContentTemplate>
</atlas:UpdatePanel>

aspx.vb file

div1.visible = false

Would trigger error: error BC30451: Name 'div1' is not declared. But it would run ok and the div would be invisible.

Is there anything like:Div div1 =upTest.FindControl("div1") as Div;. (although the DIV is not a control, or is it?)

so i don't get the errors or what can i do?? Is this bug gonna be fixed??

Thanks,

Diego

Maybe instead of using <div id="div1" runat="server">, try using <asp:Panel id="panel1" runat="server"> because they are rendered as divs in the emitted html. I didn't try it but you should be able to search using the FindControl method for the panel control.


It's an option, but feel more comfortable having control of the rendered html, so if there is a way it will be great, if not, this approach (if it works) will do it.

I don't think it's a good idea to refer to the div by its name directly. You should do document.getElementById('div1') to get to it. The main reason is that since it's in the UpdatePanel it can get updated, and I think that when that happens the direct reference that you were using will break.

Thanks,

Eilon

No comments:

Post a Comment