How to initialize a page in Page_Load() event?

G

Guest

Hi, friends,

In Page_Load() events, I want to initialize this web page with values I
retrieved from DB.

For example, for the element <INPUT type="text" id="firstName" .../>, I want
to make its value equal to "John".

So, in C#, I did:
this.firstName = dbrow["firstName"].ToString();
and, it did not work.

What should I do? Any sample code? Thanks.
 
M

Marina

What does 'it did not work' mean? That could mean one of any number of
things, and if you want constructive help, you will have to not be vague in
your question. You need to tell us exactly how/when you are getting your
data, what you expect to happen, what actually does happen, and the exact
error message if any.
 
G

Guest

when I run it, I got error message:

C:\Inetpub\wwwroot\mes\Admin\NewUser.aspx.cs(53): 'mes.Admin.NewUser' does
not contain a definition for 'firstName'

but in HTML view, I did have:

<TD><INPUT id="firstName" style="WIDTH: 204px; HEIGHT: 25px" type="text"
size="28" name="fName"></TD>


Marina said:
What does 'it did not work' mean? That could mean one of any number of
things, and if you want constructive help, you will have to not be vague in
your question. You need to tell us exactly how/when you are getting your
data, what you expect to happen, what actually does happen, and the exact
error message if any.

Andrew said:
Hi, friends,

In Page_Load() events, I want to initialize this web page with values I
retrieved from DB.

For example, for the element <INPUT type="text" id="firstName" .../>, I
want
to make its value equal to "John".

So, in C#, I did:
this.firstName = dbrow["firstName"].ToString();
and, it did not work.

What should I do? Any sample code? Thanks.
 
M

Marina

This is actually a compile time message. Not a runtime error.

So, first off, any HTML tag you want to access in server side code needs to
have a runat="server" on it. You then need to declare a corresponding
variable. This would be automatically done for you if you had dragged the
control onto the designer surfaces at design time.

Additionally, setting an INPUT control to a string value makes no logical
sense. You would want to set its Value property, not the actual object.

I recommend you do some some reading on the ASP.NET server side control
model before going too much further down this path.

Andrew said:
when I run it, I got error message:

C:\Inetpub\wwwroot\mes\Admin\NewUser.aspx.cs(53): 'mes.Admin.NewUser' does
not contain a definition for 'firstName'

but in HTML view, I did have:

<TD><INPUT id="firstName" style="WIDTH: 204px; HEIGHT: 25px" type="text"
size="28" name="fName"></TD>


Marina said:
What does 'it did not work' mean? That could mean one of any number of
things, and if you want constructive help, you will have to not be vague
in
your question. You need to tell us exactly how/when you are getting your
data, what you expect to happen, what actually does happen, and the exact
error message if any.

Andrew said:
Hi, friends,

In Page_Load() events, I want to initialize this web page with values I
retrieved from DB.

For example, for the element <INPUT type="text" id="firstName" .../>, I
want
to make its value equal to "John".

So, in C#, I did:
this.firstName = dbrow["firstName"].ToString();
and, it did not work.

What should I do? Any sample code? Thanks.
 
G

Guest

Thanks.

Just wonder if there is any performance difference when comparing using HTML
controls and using Web Form controls. For example, <INPUT type="text".../> vs
<asp:TextBox.../>? Why?

Marina said:
This is actually a compile time message. Not a runtime error.

So, first off, any HTML tag you want to access in server side code needs to
have a runat="server" on it. You then need to declare a corresponding
variable. This would be automatically done for you if you had dragged the
control onto the designer surfaces at design time.

Additionally, setting an INPUT control to a string value makes no logical
sense. You would want to set its Value property, not the actual object.

I recommend you do some some reading on the ASP.NET server side control
model before going too much further down this path.

Andrew said:
when I run it, I got error message:

C:\Inetpub\wwwroot\mes\Admin\NewUser.aspx.cs(53): 'mes.Admin.NewUser' does
not contain a definition for 'firstName'

but in HTML view, I did have:

<TD><INPUT id="firstName" style="WIDTH: 204px; HEIGHT: 25px" type="text"
size="28" name="fName"></TD>


Marina said:
What does 'it did not work' mean? That could mean one of any number of
things, and if you want constructive help, you will have to not be vague
in
your question. You need to tell us exactly how/when you are getting your
data, what you expect to happen, what actually does happen, and the exact
error message if any.

Hi, friends,

In Page_Load() events, I want to initialize this web page with values I
retrieved from DB.

For example, for the element <INPUT type="text" id="firstName" .../>, I
want
to make its value equal to "John".

So, in C#, I did:
this.firstName = dbrow["firstName"].ToString();
and, it did not work.

What should I do? Any sample code? Thanks.
 
M

Marina

They are different objects, the textbox will eventually get streamed out as
an INPUT anyway. I don't know about the performance differences, I'm
guessing minimal if any. Nothing to be concerned about in any case, because
if there are any differences, it won't be anything a user would notice.

Andrew said:
Thanks.

Just wonder if there is any performance difference when comparing using
HTML
controls and using Web Form controls. For example, <INPUT type="text".../>
vs
<asp:TextBox.../>? Why?

Marina said:
This is actually a compile time message. Not a runtime error.

So, first off, any HTML tag you want to access in server side code needs
to
have a runat="server" on it. You then need to declare a corresponding
variable. This would be automatically done for you if you had dragged
the
control onto the designer surfaces at design time.

Additionally, setting an INPUT control to a string value makes no logical
sense. You would want to set its Value property, not the actual object.

I recommend you do some some reading on the ASP.NET server side control
model before going too much further down this path.

Andrew said:
when I run it, I got error message:

C:\Inetpub\wwwroot\mes\Admin\NewUser.aspx.cs(53): 'mes.Admin.NewUser'
does
not contain a definition for 'firstName'

but in HTML view, I did have:

<TD><INPUT id="firstName" style="WIDTH: 204px; HEIGHT: 25px"
type="text"
size="28" name="fName"></TD>


:

What does 'it did not work' mean? That could mean one of any number of
things, and if you want constructive help, you will have to not be
vague
in
your question. You need to tell us exactly how/when you are getting
your
data, what you expect to happen, what actually does happen, and the
exact
error message if any.

Hi, friends,

In Page_Load() events, I want to initialize this web page with
values I
retrieved from DB.

For example, for the element <INPUT type="text" id="firstName"
.../>, I
want
to make its value equal to "John".

So, in C#, I did:
this.firstName = dbrow["firstName"].ToString();
and, it did not work.

What should I do? Any sample code? Thanks.
 
G

Guest

Nothing to be concerned about in any case, because
if there are any differences, it won't be anything a user would notice.

I hope so. Could you make a research on it? If there is any difference, very
small though, but it could be a big problem if a server or a server farm is
hit hundreds or thousands times per second, especially when each page has
tens such kinds of controls. If you do, could you let me know the results: my
email is (e-mail address removed)? Thanks a lot.

Marina said:
They are different objects, the textbox will eventually get streamed out as
an INPUT anyway. I don't know about the performance differences, I'm
guessing minimal if any. Nothing to be concerned about in any case, because
if there are any differences, it won't be anything a user would notice.

Andrew said:
Thanks.

Just wonder if there is any performance difference when comparing using
HTML
controls and using Web Form controls. For example, <INPUT type="text".../>
vs
<asp:TextBox.../>? Why?

Marina said:
This is actually a compile time message. Not a runtime error.

So, first off, any HTML tag you want to access in server side code needs
to
have a runat="server" on it. You then need to declare a corresponding
variable. This would be automatically done for you if you had dragged
the
control onto the designer surfaces at design time.

Additionally, setting an INPUT control to a string value makes no logical
sense. You would want to set its Value property, not the actual object.

I recommend you do some some reading on the ASP.NET server side control
model before going too much further down this path.

when I run it, I got error message:

C:\Inetpub\wwwroot\mes\Admin\NewUser.aspx.cs(53): 'mes.Admin.NewUser'
does
not contain a definition for 'firstName'

but in HTML view, I did have:

<TD><INPUT id="firstName" style="WIDTH: 204px; HEIGHT: 25px"
type="text"
size="28" name="fName"></TD>


:

What does 'it did not work' mean? That could mean one of any number of
things, and if you want constructive help, you will have to not be
vague
in
your question. You need to tell us exactly how/when you are getting
your
data, what you expect to happen, what actually does happen, and the
exact
error message if any.

Hi, friends,

In Page_Load() events, I want to initialize this web page with
values I
retrieved from DB.

For example, for the element <INPUT type="text" id="firstName"
.../>, I
want
to make its value equal to "John".

So, in C#, I did:
this.firstName = dbrow["firstName"].ToString();
and, it did not work.

What should I do? Any sample code? Thanks.
 
M

Marina

Umm... you want me to do research for an issue you are having?

If you are not comfortable with the performance differences between
controls, then you should do the research.

Andrew said:
Nothing to be concerned about in any case, because
if there are any differences, it won't be anything a user would notice.

I hope so. Could you make a research on it? If there is any difference,
very
small though, but it could be a big problem if a server or a server farm
is
hit hundreds or thousands times per second, especially when each page has
tens such kinds of controls. If you do, could you let me know the results:
my
email is (e-mail address removed)? Thanks a lot.

Marina said:
They are different objects, the textbox will eventually get streamed out
as
an INPUT anyway. I don't know about the performance differences, I'm
guessing minimal if any. Nothing to be concerned about in any case,
because
if there are any differences, it won't be anything a user would notice.

Andrew said:
Thanks.

Just wonder if there is any performance difference when comparing using
HTML
controls and using Web Form controls. For example, <INPUT
type="text".../>
vs
<asp:TextBox.../>? Why?

:

This is actually a compile time message. Not a runtime error.

So, first off, any HTML tag you want to access in server side code
needs
to
have a runat="server" on it. You then need to declare a corresponding
variable. This would be automatically done for you if you had dragged
the
control onto the designer surfaces at design time.

Additionally, setting an INPUT control to a string value makes no
logical
sense. You would want to set its Value property, not the actual
object.

I recommend you do some some reading on the ASP.NET server side
control
model before going too much further down this path.

when I run it, I got error message:

C:\Inetpub\wwwroot\mes\Admin\NewUser.aspx.cs(53):
'mes.Admin.NewUser'
does
not contain a definition for 'firstName'

but in HTML view, I did have:

<TD><INPUT id="firstName" style="WIDTH: 204px; HEIGHT: 25px"
type="text"
size="28" name="fName"></TD>


:

What does 'it did not work' mean? That could mean one of any number
of
things, and if you want constructive help, you will have to not be
vague
in
your question. You need to tell us exactly how/when you are getting
your
data, what you expect to happen, what actually does happen, and the
exact
error message if any.

Hi, friends,

In Page_Load() events, I want to initialize this web page with
values I
retrieved from DB.

For example, for the element <INPUT type="text" id="firstName"
.../>, I
want
to make its value equal to "John".

So, in C#, I did:
this.firstName = dbrow["firstName"].ToString();
and, it did not work.

What should I do? Any sample code? Thanks.
 
G

Guest

I thought it was a interesting high level concerns, not my own issue, I do
not have servers being hit hundreds/thousands times, :)...

What I can see the benefit here is: For a progrmmer, one will know when to
use more HTML controls and when to Web Form controls, based on the research
results.

BTW, my guess is: Web Form controls is slower, try to avoid using them....

Marina said:
Umm... you want me to do research for an issue you are having?

If you are not comfortable with the performance differences between
controls, then you should do the research.

Andrew said:
Nothing to be concerned about in any case, because
if there are any differences, it won't be anything a user would notice.

I hope so. Could you make a research on it? If there is any difference,
very
small though, but it could be a big problem if a server or a server farm
is
hit hundreds or thousands times per second, especially when each page has
tens such kinds of controls. If you do, could you let me know the results:
my
email is (e-mail address removed)? Thanks a lot.

Marina said:
They are different objects, the textbox will eventually get streamed out
as
an INPUT anyway. I don't know about the performance differences, I'm
guessing minimal if any. Nothing to be concerned about in any case,
because
if there are any differences, it won't be anything a user would notice.

Thanks.

Just wonder if there is any performance difference when comparing using
HTML
controls and using Web Form controls. For example, <INPUT
type="text".../>
vs
<asp:TextBox.../>? Why?

:

This is actually a compile time message. Not a runtime error.

So, first off, any HTML tag you want to access in server side code
needs
to
have a runat="server" on it. You then need to declare a corresponding
variable. This would be automatically done for you if you had dragged
the
control onto the designer surfaces at design time.

Additionally, setting an INPUT control to a string value makes no
logical
sense. You would want to set its Value property, not the actual
object.

I recommend you do some some reading on the ASP.NET server side
control
model before going too much further down this path.

when I run it, I got error message:

C:\Inetpub\wwwroot\mes\Admin\NewUser.aspx.cs(53):
'mes.Admin.NewUser'
does
not contain a definition for 'firstName'

but in HTML view, I did have:

<TD><INPUT id="firstName" style="WIDTH: 204px; HEIGHT: 25px"
type="text"
size="28" name="fName"></TD>


:

What does 'it did not work' mean? That could mean one of any number
of
things, and if you want constructive help, you will have to not be
vague
in
your question. You need to tell us exactly how/when you are getting
your
data, what you expect to happen, what actually does happen, and the
exact
error message if any.

Hi, friends,

In Page_Load() events, I want to initialize this web page with
values I
retrieved from DB.

For example, for the element <INPUT type="text" id="firstName"
.../>, I
want
to make its value equal to "John".

So, in C#, I did:
this.firstName = dbrow["firstName"].ToString();
and, it did not work.

What should I do? Any sample code? Thanks.
 
B

Bruce Barker

you have several issues.

1) if you did not specifiy a name for a textbox, or the browser will not
post it back (becuase there is no name for ther name/value pair).

2) you need a runat=server attribute for the code behind to see (the id
attribute is used to create the name in the code behind)

3) the html input control has a Value property.

try:

<INPUT type="text" id="firstName" name="firstName" runat=server />

in onload

if (!IsPostback)
this.firstName.Value = dbrow["firstName"].ToString();

-- bruce (sqlwork.com)
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top