代码隐藏问题 [英] codebehind question

查看:49
本文介绍了代码隐藏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在aspx页面后面使用类代码,那么从代码隐藏类到我的aspx页面获取

数据的最佳方法是什么?


我知道数据绑定,但有没有更基本的方法来引用变量或调用getter来获得



提前感谢

解决方案

只需删除标签(或任何支持文本/数据表示的控件)。

对于显示文本的控件(如文本框或标签),只需将控件的

文本属性设置为代码隐藏中的值。对于

类似复选框或单选按钮,你会根据代码隐藏中的布尔值设置

的checked属性。

Karl Hungus < NN ********* @ hotmail.com>在消息中写道

news:ud *********************** @ twister.nyc.rr.com。 ..

如果我在aspx页面后面使用代码,那么将代码隐藏类中的数据导入我的aspx页面的最佳方法是什么?
我知道数据绑定,但有没有更基本的方法只需
引用变量或调用getter?

提前感谢



好的,那清楚。但是我如何引用代码隐藏的价值。


假设我有一个代码隐藏对象,我在aspx页面中实例化

在pageload事件中喜欢


void Page_Load(Object Src,EventArgs E){


XMLManager xman = new XMLManager();

xman.ReadXML();


}

XMLManager类中的
我有一个


public String testStr;


我设置....如何检索该值?

" Scott M." < S - *** @ BADSPAMsnet.net>在消息中写道

news:uN ************** @ TK2MSFTNGP12.phx.gbl ...

只需删除一个标签(或者任何支持文本/数据表示的控件。
对于显示文本的控件(如文本框或标签),只需将控件的
文本属性设置为代码隐藏中的值即可。对于像复选框或单选按钮这样的东西,你会根据代码隐藏中的布尔值设置控件的checked属性



不要认为它是拉动代码隐藏到aspx

页面的值。而是推从代码隐藏到aspx页面的值。


换句话说,你不需要从aspx页面获取代码隐藏值testStr

。相反,在aspx页面上放置一个标签(例如),在

中,代码隐藏的Page_Load事件将字符串值放在标签中。


In .aspx页面:


< ASP:LABEL ID =" lblDataHolder" RUNAT =" Sever">< / ASP:LABEL>


在代码隐藏中:


void Page_Load(Object Src,EventArgs E){


XMLManager xman = new XMLManager();

xman.ReadXML();


/ /它接受类中的公共字符串值并将其放入网页上的

标签

lblDataHolder.Text = xman.testStr;


}


-Scott


" Karl Hungus" < NN ********* @ hotmail.com>在消息中写道

新闻:Ek *********************** @ twister.nyc.rr.com。 ..

好的,那很清楚。但是我如何引用代码隐藏的价值。

让我说我有一个代码隐藏对象,我在页面加载事件中的aspx页面实例化
void Page_Load(Object Src,EventArgs E){

XMLManager xman = new XMLManager();
xman.ReadXML();

}

在XMLManager类中我有一个

public String testStr;

我设置....如何检索该值?

Scott M. < S - *** @ BADSPAMsnet.net>在消息中写道
新闻:uN ************** @ TK2MSFTNGP12.phx.gbl ...

只需删除一个标签(或任何控件,支持文本/数据
表示)。对于显示文本的控件(如文本框或标签),只需将控件的
文本属性设置为代码隐藏中的值即可。对于像复选框或单选按钮这样的东西,你会根据代码隐藏中的布尔值设置

控件的checked属性


。 blockquote>



If I use a code behind class for an aspx page, what is the best way to get
data from the codebehind class into my aspx page?

I know about databinding, but is there a more basic way of just referencing
the variables or calling getters?

thanks in advance

解决方案

Just drop a label (or any control that support text/data representation).
For a control that displays text (like a textbox or label), just set the
text property of the control to the value from the codebehind. For
something like a checkbox or radiobutton, you''d set the checked property of
the control based on the boolean value in the codebehind.
"Karl Hungus" <nn*********@hotmail.com> wrote in message
news:ud***********************@twister.nyc.rr.com. ..

If I use a code behind class for an aspx page, what is the best way to get
data from the codebehind class into my aspx page?

I know about databinding, but is there a more basic way of just referencing the variables or calling getters?

thanks in advance



OK, thats clear. But how do I reference the value of the codebehind.

lets say I have a codebehind object, that I instantiate in the aspx page
within the pageload event like

void Page_Load(Object Src, EventArgs E) {

XMLManager xman = new XMLManager();
xman.ReadXML();

}

within the XMLManager class I have a

public String testStr;

which I set....how do I retrieve that value?
"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:uN**************@TK2MSFTNGP12.phx.gbl...

Just drop a label (or any control that support text/data representation).
For a control that displays text (like a textbox or label), just set the
text property of the control to the value from the codebehind. For
something like a checkbox or radiobutton, you''d set the checked property of the control based on the boolean value in the codebehind.



Don''t think of it as "pulling" the value from the codebehind to the aspx
page. Instead "push" the value from the codebehind to the aspx page.

In other words, you wouldn''t need to grab the codebehind value testStr from
the aspx page. Instead, place a label (for example) on the aspx page and in
the Page_Load event of the codebehind place the string value in the label.

In the .aspx page:

<ASP:LABEL ID="lblDataHolder" RUNAT="Sever"></ASP:LABEL>

In the codebehind:

void Page_Load(Object Src, EventArgs E) {

XMLManager xman = new XMLManager();
xman.ReadXML();

//This takes the public string value in the class and places it into the
label on the web page
lblDataHolder.Text = xman.testStr;

}

-Scott

"Karl Hungus" <nn*********@hotmail.com> wrote in message
news:Ek***********************@twister.nyc.rr.com. ..

OK, thats clear. But how do I reference the value of the codebehind.

lets say I have a codebehind object, that I instantiate in the aspx page
within the pageload event like

void Page_Load(Object Src, EventArgs E) {

XMLManager xman = new XMLManager();
xman.ReadXML();

}

within the XMLManager class I have a

public String testStr;

which I set....how do I retrieve that value?
"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:uN**************@TK2MSFTNGP12.phx.gbl...

Just drop a label (or any control that support text/data representation). For a control that displays text (like a textbox or label), just set the
text property of the control to the value from the codebehind. For
something like a checkbox or radiobutton, you''d set the checked property


of

the control based on the boolean value in the codebehind.




这篇关于代码隐藏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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