B
brett
I have an aspx page with a user control (uc1) on it. There is a DIV
tag in the user control and I'd like to set its width. In uc1, I have
a private string varible with a value of "100px". In the DIV I do
this:
<div class="box" style="width: <%= uc1.boxWidth %>;">
However, when the aspx page loads, I immediately get an error that uc1
doesn't exists. It occurs before the aspx constructor or PreInit()
occur. How can I get the above variable to render client side?
I did try something different. After adding runat=server and giving
it an Id, if I try to assign it in the code behind, it isn't
recognized because the control isn't created anywhere. I could drop
in an ASP panel there and probably make it do what the DIV does. I'll
also have code behind access. But how do you take an HTML element,
give it a runat=server and then be able to reference it in the code
behind? That control has to be created somewhere for the code behind
reference.
Here's what it looks like after the above modifications:
<div runat="server" id="mainbox" class="box" style="width: 125px">
If there is a generally better way to do it, please suggest.
Thanks,
Brett
tag in the user control and I'd like to set its width. In uc1, I have
a private string varible with a value of "100px". In the DIV I do
this:
<div class="box" style="width: <%= uc1.boxWidth %>;">
However, when the aspx page loads, I immediately get an error that uc1
doesn't exists. It occurs before the aspx constructor or PreInit()
occur. How can I get the above variable to render client side?
I did try something different. After adding runat=server and giving
it an Id, if I try to assign it in the code behind, it isn't
recognized because the control isn't created anywhere. I could drop
in an ASP panel there and probably make it do what the DIV does. I'll
also have code behind access. But how do you take an HTML element,
give it a runat=server and then be able to reference it in the code
behind? That control has to be created somewhere for the code behind
reference.
Here's what it looks like after the above modifications:
<div runat="server" id="mainbox" class="box" style="width: 125px">
If there is a generally better way to do it, please suggest.
Thanks,
Brett