Response.Write() ??

C

Chris

Hi,

On a webform do I have a label, a textBox (txtName) and a submit-button (all
asp server controls) :

Upon pressing the button do I write the entered name in the html-output
stream (at server site) :


private void idSubmit_Click(object sender, System.EventArgs e)
{
string str = "Thanks for filling out our survey " + txtName.Text +
"<br>";
Response.Write(str);
}

That works when I execute this in a brower but I see all the controls
displayed as well.

How can I only display the entered name as a reponse ?

thnx
Chris
 
H

Hugo Wetterberg

Hi,

On a webform do I have a label, a textBox (txtName) and a submit-button (all
asp server controls) :

Upon pressing the button do I write the entered name in the html-output
stream (at server site) :


private void idSubmit_Click(object sender, System.EventArgs e)
{
string str = "Thanks for filling out our survey " + txtName.Text +
"<br>";
Response.Write(str);
}

That works when I execute this in a brower but I see all the controls
displayed as well.

How can I only display the entered name as a reponse ?

thnx
Chris

First of all: buy an ASP.NET book to read in on the fundamentals.

If you want to hide controls, use:
idSubmit.Visible=false;
txtName.Visible=false;

You should use a label control to output your message to the user. The
message may look ok, but the Click event is handled before Page.Render()
causing something like:

Thanks for filling out our survey Doe<BR>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
....
</HTML>

Which is less than perfect.

/Hugo
 
C

Chris

ok, thanks.

is there any way you can prevent a control from rendering itself at runtime
(based on a if-condition) ?
 
H

Hugo Wetterberg

Yes, of course. Assume that the user queries you page using parameters in
the uri:"testpage.aspx?hideButton=yes"

then you can test this in the Page Load handler:
if(Request["hideButton"]=="yes")
idSubmit.Visible=false;

Or a more irrational condition if you want to hide the button at night:
if(DateTime.Now.Hour>20 || DateTime.Now.Hour<6)
idSubmit.Visible=false;

/Hugo
 
M

Mark Fitzpatrick

Most of them have a visible and enabled attributes. You can set both of
these to false to hide and disable them. They both have to be set to false
really in order for best performance and for best results.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
E

Eliyahu Goldin

Don't write to response (although you can if you wish). Rather prepare all
you want to render in design time and manipulate Visible property.

Eliyahu
 
C

Chris

apart from setting the visible property to false, is there a way to do that
in the Page-PreRender-event handler ?

some check allowing me to prevent the rendering of a specific control on the
page
thanks
Chris

Hugo Wetterberg said:
Yes, of course. Assume that the user queries you page using parameters in
the uri:"testpage.aspx?hideButton=yes"

then you can test this in the Page Load handler:
if(Request["hideButton"]=="yes")
idSubmit.Visible=false;

Or a more irrational condition if you want to hide the button at night:
if(DateTime.Now.Hour>20 || DateTime.Now.Hour<6)
idSubmit.Visible=false;

/Hugo

ok, thanks.

is there any way you can prevent a control from rendering itself at runtime
(based on a if-condition) ?

submit-button
(all
 
H

Hugo Wetterberg

I don't know what you're after, setting Visible to false prevents the
rendering of the control. The metod void Render(HtmlTextWriter) for the
control never gets executed. It doesn't matter if you do this in Load or
PreRender, rendering is completely prevented anyway.

/Hugo

apart from setting the visible property to false, is there a way to do that
in the Page-PreRender-event handler ?

some check allowing me to prevent the rendering of a specific control on the
page
thanks
Chris

Hugo Wetterberg said:
Yes, of course. Assume that the user queries you page using parameters in
the uri:"testpage.aspx?hideButton=yes"

then you can test this in the Page Load handler:
if(Request["hideButton"]=="yes")
idSubmit.Visible=false;

Or a more irrational condition if you want to hide the button at night:
if(DateTime.Now.Hour>20 || DateTime.Now.Hour<6)
idSubmit.Visible=false;

/Hugo

ok, thanks.

is there any way you can prevent a control from rendering itself at runtime
(based on a if-condition) ?

On Thu, 09 Sep 2004 11:28:50 GMT, Chris wrote:

Hi,

On a webform do I have a label, a textBox (txtName) and a submit-button
(all
asp server controls) :

Upon pressing the button do I write the entered name in the html-output
stream (at server site) :


private void idSubmit_Click(object sender, System.EventArgs e)
{
string str = "Thanks for filling out our survey " + txtName.Text +
"<br>";
Response.Write(str);
}

That works when I execute this in a brower but I see all the controls
displayed as well.

How can I only display the entered name as a reponse ?

thnx
Chris

First of all: buy an ASP.NET book to read in on the fundamentals.

If you want to hide controls, use:
idSubmit.Visible=false;
txtName.Visible=false;

You should use a label control to output your message to the user. The
message may look ok, but the Click event is handled before Page.Render()
causing something like:

Thanks for filling out our survey Doe<BR>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
...
</HTML>

Which is less than perfect.

/Hugo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top