如何在Page_Load()事件中初始化页面? [英] How to initialize a page in Page_Load() event?

查看:130
本文介绍了如何在Page_Load()事件中初始化页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,


在Page_Load()事件中,我想初始化这个网页,其值是从数据库中检索到的。




例如,对于元素< INPUT type =" text" ID = QUOT;&的firstName QUOT; ... />,我希望

使其值等于John。


因此,在C#中,我做了:

this.firstName = dbrow [" firstName"]。ToString();

,它不起作用。


什么我该怎么办?任何示例代码?谢谢。

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
之一,如果你想要建设性的帮助,你的问题就不必含糊。

你的问题。您需要确切地告诉我们您何时/何时获得

数据,您期望发生什么,实际发生了什么,以及确切的

错误消息(如果有的话)。


" Andrew" <安**** @ discussions.microsoft.com>在消息中写道

新闻:C6 ********************************** @ microsof t.com ...
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...
朋友们,

在Page_Load()事件中,我想用从数据库中检索的值来初始化这个网页。

例如,对于元素< INPUT type =" text" ID = QUOT;&的firstName QUOT; ... />,我希望
使其值等于John。

所以,在C#中,我做到了:
这个。 firstName = dbrow [" firstName"]。ToString();
并且,它不起作用。

我该怎么办?任何示例代码?谢谢。
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.



当我运行它时,我收到错误消息:


C:\ Inetpub \ wwwroot \mes\Admin \NewUser.aspx.cs(53):''mes.Admin.NewUser''确实

不包含''firstName'的定义'


但在HTML视图中,我确实有:


< TD>< INPUT id =" firstName" style =" WIDTH:204px;高度:25px type =" text"

size =" 28" name =" fName">< / TD>

" Marina"写道:
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:
它不起作用是什么意思?这可能意味着任何一件事情,如果你想要建设性的帮助,你的问题就不会含糊不清。您需要准确地告诉我们您获取数据的时间/时间,您期望发生的事情,实际发生的事情以及确切的错误消息(如果有的话)。

"安德鲁" <安**** @ discussions.microsoft.com>在消息中写道
新闻:C6 ********************************** @ microsof t.com。 ..
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...
好友,

在Page_Load()事件中,我想用从数据库中检索的值来初始化这个网页。

例如,对于元素< INPUT type =" text" ID = QUOT;&的firstName QUOT; ... />,我希望
使其值等于John。

所以,在C#中,我做到了:
这个。 firstName = dbrow [" firstName"]。ToString();
并且,它不起作用。

我该怎么办?任何示例代码?谢谢。
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.




这实际上是一个编译时消息。不是运行时错误。


因此,首先,您要在服务器端代码中访问的任何HTML标记需要

有一个runat =" server" ;在上面。然后,您需要声明相应的

变量。如果您在设计时将

控件拖到设计器表面上,这将自动完成。


此外,将INPUT控件设置为字符串价值不合逻辑

感。你想要设置它的Value属性,而不是实际的对象。


我建议你在ASP.NET服务器端控件上做一些阅读

model在沿着这条道路走得太远之前。


" Andrew" <安**** @ discussions.microsoft.com>在消息中写道

新闻:8A ********************************** @ microsof t.com ...
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...
当我运行它时,我收到了错误消息:

C:\Inetpub \wwwroot \\\\\\\\\\\\\\\\\\ aspx.cs(53):''mes.Admin.NewUser''
不包含''firstName'的定义'

但在HTML视图中,我确实有:

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

" Marina"写道:
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:
它不起作用是什么意思?这可能意味着任何一件事,如果你想要建设性的帮助,你将不得不在你的问题中含糊不清。您需要准确地告诉我们您获取数据的时间/时间,您期望发生的事情,实际发生的事情以及确切的错误消息(如果有的话)。

"安德鲁" <安**** @ discussions.microsoft.com>在消息中写道
新闻:C6 ********************************** @ microsof t.com。 ..
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...
>朋友们,
>
>在Page_Load()事件中,我想用值I />>初始化此网页。从DB检索。
>
>例如,对于元素< INPUT type =" text" ID = QUOT;&的firstName QUOT; ... /> ;,我
>想要
>使其价值等于约翰。
>
>所以,在C#中,我做了:
> this.firstName = dbrow [" firstName"]。ToString();
>并且,它不起作用。
>
>我该怎么办?任何示例代码?谢谢。
>
> 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.
>




这篇关于如何在Page_Load()事件中初始化页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆