473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to initialize a page in Page_Load() event?

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.

Nov 19 '05 #1
10 2079
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" <An****@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
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.

Nov 19 '05 #2
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" wrote:
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" <An****@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
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.


Nov 19 '05 #3
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" <An****@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
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" wrote:
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" <An****@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
> 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.
>


Nov 19 '05 #4
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" wrote:
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" <An****@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
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" wrote:
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" <An****@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
> 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.
>


Nov 19 '05 #5
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" <An****@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
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" wrote:
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" <An****@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
> 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" wrote:
>
>> 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" <An****@discussions.microsoft.com> wrote in message
>> news:C6**********************************@microsof t.com...
>> > 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.
>> >
>>
>>
>>


Nov 19 '05 #6
Andrew,

I agree with Marina, you should look into some of the tutorials.
Try www.gotdotnet.com (click the "Toolbox" on the bottom left).

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Andrew" <An****@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
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.

Nov 19 '05 #7
>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 vb*****@yahoo.com? Thanks a lot.

"Marina" wrote:
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" <An****@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
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" wrote:
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" <An****@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
> 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" wrote:
>
>> 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" <An****@discussions.microsoft.com> wrote in message
>> news:C6**********************************@microsof t.com...
>> > 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.
>> >
>>
>>
>>


Nov 19 '05 #8
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" <An****@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
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 vb*****@yahoo.com? Thanks a lot.

"Marina" wrote:
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" <An****@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
> 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" wrote:
>
>> 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" <An****@discussions.microsoft.com> wrote in message
>> news:8A**********************************@microsof t.com...
>> > 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" wrote:
>> >
>> >> 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" <An****@discussions.microsoft.com> wrote in message
>> >> news:C6**********************************@microsof t.com...
>> >> > 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.
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #9
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" wrote:
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" <An****@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
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 vb*****@yahoo.com? Thanks a lot.

"Marina" wrote:
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" <An****@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
> 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" wrote:
>
>> 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" <An****@discussions.microsoft.com> wrote in message
>> news:8A**********************************@microsof t.com...
>> > 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" wrote:
>> >
>> >> 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" <An****@discussions.microsoft.com> wrote in message
>> >> news:C6**********************************@microsof t.com...
>> >> > 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.
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #10
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)
"Andrew" <An****@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
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.

Nov 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: WFB | last post by:
Hi, I have a base class from which all of my pages derive (ABCBasePage). For example, ABCCustomerSelect Inherits ABCPasePage. I would now like to have ABCPocketSelect which should inherit from...
6
by: MooreSmnith | last post by:
When I navigate to the next page using Response.Rediect("MyNextPage.aspx") current page Page_Load event is called. What I may wrongly understood is that post back will happen whenever there is any...
13
by: Veeresh | last post by:
I am using .Net 1.1. How to expire an .aspx page? I think I have to use HttpCachePolicy class for this. But not sure how to use and where to this code to work. Is it in Page_load event. Thanks...
4
by: Guadala Harry | last post by:
Just wondering what could cause this: I have observed that when first opening an aspx page, the Page_Load event fires as expected. Then I go to other pages in the site. When returning to any page...
1
by: Rippo | last post by:
Hi I have a Master page that opens up a db connection, performs a couple of global routines in the page_load event. All of my other web pages in my web app then inherits this Master Page I...
2
by: Justin Beckwith | last post by:
Hey all, to keep some common functionality together, I am making all of my web forms inherit from one base class, which inherits from System.Web.UI.Page, instead of all my webforms inheriting...
2
by: Phillip N Rounds | last post by:
I'm working on a UserControl ( ASP.NET 1.1, C#, VS 2003), where I can't manage the state of multiple controls correctly. The controls have the following constraints 1: It has two possible...
0
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and...
1
by: smith387 | last post by:
What I am attempting to do is use ASP.NET with C# to create a page that will use its page_load event to initialize a button event from an Access database. Currently I am running a form in Access with...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.