标题:请教一个问题textbox.text 在类方法引用问题
只看楼主
s_xchen
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-5-16
 问题点数:0 回复次数:3 
请教一个问题textbox.text 在类方法引用问题
运行提示hairclor=tbhair.Text对非共享成员的引用要求对象引用,是什么原因,类方法不能直接引用还是那里出错,请帮帮忙?

<HTML>
    <HEAD>
        <script language="VB" runat="server">
 CLASS cx
   public hairclor as string
   public eyeclor as string
   public birthday as date
 sub setmyself(Sender As Object, E As EventArgs)
 hairclor=tbhair.Text
 eyeclor=tbeye.Text
 birthday=date(tbbir.Text)
   end sub
 end class
sub  btSubmit_click(Sender As Object, E As EventArgs)
dim week as integer
week=birthday.dayofweek
response.write(hairclor&eyeclor)
end sub
 
        </script>
    </HEAD>
    <BODY bgcolor="#cccccc">
        <font size="5">Sam's Teach Yourself in 21 Days: Day 2, Exercise 1</font><hr>
        <p>
            <form runat="server" ID="Form1">
                hair:
                <asp:textbox id="tbhair" runat="server" />
                eye:
                <asp:textbox id="tbeye" runat="server" />
                <asp:button id="btSubmit" Text="Submit" OnClick="btSubmit_Click" runat="server" />
                <P>
                    birthday:
                    <asp:TextBox id="tbbir" runat="server"></asp:TextBox>
                    &nbsp;&nbsp;&nbsp;&nbsp;</P>
                <P>&nbsp;</P>
                <P>&nbsp;</P>
            </form>
    </BODY>
</HTML>
搜索更多相关主题的帖子: Object HTML 
2011-05-16 23:24
yms123
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:0 
CLASS cx
   public hairclor as string
   public eyeclor as string
   public birthday as date
sub setmyself(Sender As Object, E As EventArgs)
hairclor=tbhair.Text
eyeclor=tbeye.Text
birthday=date(tbbir.Text)
   end sub
end class
LZ这里相当于定义了一个class而tbhair.Text并不是在这个class里,而是在网页里,所以你在class里应该是无法直接访问那个文本框的
2011-05-17 10:54
s_xchen
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-5-16
得分:0 
意思是说类里面定义函数不能直接访问html元素属性吗   
有什么办法解决,如果一定要在类中,或者一定要在类外面引用呢
2011-05-17 12:32
yms123
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:0 
你只能通过属性或构造函数来解决,不可能直接引用控件
2011-05-17 13:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-340113-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.095734 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved