Response.Write help

  • Thread starter Thread starter pers
  • Start date Start date
P

pers

Hello
I want to know that can I use Response.Write for ouput value of a property
for instance <Td width='<%= StaticFunction() %>' />

thanks in advance
 
Hello
I want to know that can I use Response.Write for ouput value of a property
for instance <Td  width='<%=  StaticFunction() %>' />

thanks in advance

protected string StaticFunction()
{
return "50";
}
 
I read that as...

Response.Write("<Td width='<%= StaticFunction() %>' />")

though I could be wrong...

If that is the case, then add to what Alexy wrote...

Response.Write("<Td width='" + StaticFunction() + "' />")


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


Hello
I want to know that can I use Response.Write for ouput value of a property
for instance <Td width='<%= StaticFunction() %>' />

thanks in advance

protected string StaticFunction()
{
return "50";
}
 
Lets not start the top post / bottom post debate. I post where my cursor is
placed when I respond. If the rules change, tell MS.

I know how the = works, I read his question as how to write out the whole
string of <Td width='<%= StaticFunction() %>' /> in a Response.Write
statement, which of course won't really work... the <%=....%> would require
some form of very late binding to evaluate the StaticFunction, which won't
work, hence my alternative of writing out without the <%= %>.

The question was about writing it out, not really about the rights and
wrongs of writing it in a Response.Write. If I was to be writing something
out using Response.Write, I would do it that way, alternatively, I would be
using a label or a literal to write it...

<asp:Literal id="MyLit" runat="server" Text="<%=StaticFunction()%>" />

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


Mark Rae said:
[please don't top-post]
protected string StaticFunction()
{
return "50";
}
I read that as...

Response.Write("<td width='<%= StaticFunction() %>' />")

though I could be wrong...

You are. The equals sign is shorthand for Response.Write and is used to
inject server-side content into client-side markup - that's what <%...%>
is for.

If that is the case, then add to what Alexy wrote...

Response.Write("<td width='" + StaticFunction() + "' />")

That is server-side code which is trying to inject additional characters
into the HTML stream, and should be avoided at all costs. ASP.NET is
object-orentated, not liner like ASP, and you often have very little
control over where the characters you are injecting will actually end up.
However, this problem doesn't exist in the way Alexey demonstrated because
the injected characters can only appear between the <%...%> tags.
 
pers said:
Hello
I want to know that can I use Response.Write for ouput value of a property
for instance <Td width='<%= StaticFunction() %>' />

thanks in advance

Yes.

The method that you want to call has to be protected (or public) so that
the page can reach it.
 
Back
Top