468,116 Members | 2,168 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,116 developers. It's quick & easy.

How to evaluate the dimensions of a <div>

Hello, I'm fairly new to asp.net programming (I come from a C++ background)
and am still finding some things very confusing. I wondered if anyone could
help me with the following issue.

I managed to add a handler function to my project which uses GDI+ to resize
a largish image down to an arbitray size. Now I'd like to be able to get the
required sizes programatically from the enclosing <divbut I'm struggling
to see how to do that.

For example, I have the following in a test.aspx page.

<div id="Frame" style="width:200px; height:200px;">

<img src="Resize.ashx?Image=Images/BigImage.jpg&Width=<% ???? %>&Height=<%
???? %>" >

</div>

This works fine if I just substitute = "200" for ???? but is there anything
I can put inside the <% %which will evaluate to the actual width and
height of any enclosing div?

Many Thanks for any help
Jeff
Oct 21 '08 #1
4 1346

Sorry to reply to my own post....

I figured that it probably isn't possible to get at the run time size of the
image from within the page itself, so I added some public variable which I
evaluate at page load. Now I have something like this :-

<div>
Image size = <%=Width %x <%=Height %>
<img id="myImage" runat="server"
src="Resize.ashx?Image=Images/BigImage.jpg&Width=<%=Width %>" style="width:
400px; height: 400px" />
<\div>

Stepping through the code I see that the values for Width and Height are
correctly evaluated in Page_Load and when I run the page the correct values
are substituted into the text "Image size= 400 x 400".

But unfortunately in my handler, context.Request["Width"] evaluates to
<%=Width%instead of 400.

So where am I going wrong?

Thanks for any help

Jeff

Oct 21 '08 #2
This is just literal values. If I remember you'll have to do soemthign such
:

src='<%="Resize.ashx?Image=...&Width"+Width.ToStri ng%>' to get the effect
you want. so that ASP.NET recogniez that you introduce an expression into
this property.

I don't guarantee this syntax as my personal preference is to avoid
expression in ASPX markup and to go in this my code behind file :

MyImage.src=MyExpression...

--
Patrice

"Jeff" <so*****@somewhere.coma écrit dans le message de groupe de
discussion : DD*********************@newsfe25.ams2...
>
Sorry to reply to my own post....

I figured that it probably isn't possible to get at the run time size of
the image from within the page itself, so I added some public variable
which I evaluate at page load. Now I have something like this :-

<div>
Image size = <%=Width %x <%=Height %>
<img id="myImage" runat="server"
src="Resize.ashx?Image=Images/BigImage.jpg&Width=<%=Width %>"
style="width: 400px; height: 400px" />
<\div>

Stepping through the code I see that the values for Width and Height are
correctly evaluated in Page_Load and when I run the page the correct
values are substituted into the text "Image size= 400 x 400".

But unfortunately in my handler, context.Request["Width"] evaluates to
<%=Width%instead of 400.

So where am I going wrong?

Thanks for any help

Jeff
Oct 21 '08 #3
<%= %can not be used to set properties of controls with runat=server,
only binding expression which require you also do a bind. just take the
runat=server off or set the properties in the codebehind.

by default a div is the size of its content, so there is no need to set
it. you can get its size at runtime with javascript.

-- bruce (sqlwork.com)

Jeff wrote:
Sorry to reply to my own post....

I figured that it probably isn't possible to get at the run time size of the
image from within the page itself, so I added some public variable which I
evaluate at page load. Now I have something like this :-

<div>
Image size = <%=Width %x <%=Height %>
<img id="myImage" runat="server"
src="Resize.ashx?Image=Images/BigImage.jpg&Width=<%=Width %>" style="width:
400px; height: 400px" />
<\div>

Stepping through the code I see that the values for Width and Height are
correctly evaluated in Page_Load and when I run the page the correct values
are substituted into the text "Image size= 400 x 400".

But unfortunately in my handler, context.Request["Width"] evaluates to
<%=Width%instead of 400.

So where am I going wrong?

Thanks for any help

Jeff
Oct 21 '08 #4

"Patrice" <http://www.chez.com/scribe/wrote in message
news:AD**********************************@microsof t.com...
This is just literal values. If I remember you'll have to do soemthign
such :

src='<%="Resize.ashx?Image=...&Width"+Width.ToStri ng%>' to get the effect
you want. so that ASP.NET recogniez that you introduce an expression into
this property.

I don't guarantee this syntax as my personal preference is to avoid
expression in ASPX markup and to go in this my code behind file :

MyImage.src=MyExpression...

--
Patrice
Thanks Patrice

I've tried every variation on this sort of thing

I can add something like

<%="Resize.ashx?Image=Images/BigImage.jpg&Width="+Width%>

outside of the object tags and it evaluates just as I want on the page.

But as soon as I put this sort of thing inside the < tags I get a message
like
Build (web): Server tags cannot contain <% ... %constructs.
Oh well - maybe I'm not meant to do this!

Jeff
Oct 21 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Paul Thompson | last post: by
8 posts views Thread by Daniel Hansen | last post: by
3 posts views Thread by Josef K. | last post: by
28 posts views Thread by Kent Feiler | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.