选项严格使用Ctype(发件人.... [英] Option Strict With Ctype(sender....
问题描述
你好,
我目前正在使用我们的一些aspx.vb
文件严格。我有一个函数,当一个datarepeater被绑定时,或者当选择了一个按钮时,或者在一个datarepeater上调用了一个函数。该函数接受一个
''sender''对象,根据
函数的运行方式,该对象可能属于不同类型。
在一个实例中,类型是System.Web.UI.WebControls.RepeaterItem,并且在
其他实例中,它是System.Web.UI.HtmlControls.HtmlTableCell。在我可以简单地使用sender.FindControl之前,我现在必须检查
''sender.GetType.ToString''值并使用if获取每个控件
基于此的
语句所以我可以将我的发送者对象转换为正确的类型。
这已经奏效但我不能不觉得必须有一个更容易和更整洁的
这样做的方式!
如果有人有任何建议他们会感激不尽。
非常感谢,
Carl Howarth
Hello there,
I am currently in the process of ''getting strict'' with some of our aspx.vb
files. I have a function that is called either when a datarepeater is bound
or when a button on the datareader is selected. The function accepts a
''sender'' object, which may be of a different type depending on how the
function is ran.
In one instance the type is "System.Web.UI.WebControls.RepeaterItem", and on
others it is "System.Web.UI.HtmlControls.HtmlTableCell". Where i could simply
use sender.FindControl previously, I now have to check the
''sender.GetType.ToString'' value and get each of the controls using if
statements based on this so I can cast my sender object to the correct type.
This has worked but I can''t help feeling there must be an easier and neater
way of doing this!
If anybody has any suggestions they''d be gratefully received.
Thanks very much,
Carl Howarth
推荐答案
不。你正在走上正轨。您可能希望使用DirectCast作为其更快的
等等。
-
最好的问候
无与伦比的Mr Newbie o?o
" Carl Howarth" <钙********* @ discussions.microsoft.com>在留言中写道
新闻:A6 ********************************** @ microsof t.com ...
Nope. You are on track. You may want to use DirectCast instead as its faster
amongst other things.
--
Best Regards
The Inimitable Mr Newbie o?o
"Carl Howarth" <Ca*********@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com...
你好,
我目前正在使用我们的一些aspx.vb
文件'严格'' 。我有一个函数,当一个datarepeater绑定
或选择了datareader上的一个按钮时调用。该函数接受一个
''sender''对象,根据
函数的运行方式,该对象可能属于不同类型。
在一个实例中,类型为 System.Web.UI.WebControls.RepeaterItem"和
在其他人身上是System.Web.UI.HtmlControls.HtmlTableCell。我可以在以前简单地使用sender.FindControl,我现在必须检查
''sender.GetType.ToString''值,并使用if
获取每个控件基于此的陈述,所以我可以将我的发送者对象转换为正确的
类型。
这已经奏效,但我不能不觉得必须有一个更容易和
的整洁器
这样做的方式!
如果有人有任何建议他们会感激不尽。
非常感谢,
Carl Howarth
Hello there,
I am currently in the process of ''getting strict'' with some of our aspx.vb
files. I have a function that is called either when a datarepeater is
bound
or when a button on the datareader is selected. The function accepts a
''sender'' object, which may be of a different type depending on how the
function is ran.
In one instance the type is "System.Web.UI.WebControls.RepeaterItem", and
on
others it is "System.Web.UI.HtmlControls.HtmlTableCell". Where i could
simply
use sender.FindControl previously, I now have to check the
''sender.GetType.ToString'' value and get each of the controls using if
statements based on this so I can cast my sender object to the correct
type.
This has worked but I can''t help feeling there must be an easier and
neater
way of doing this!
If anybody has any suggestions they''d be gratefully received.
Thanks very much,
Carl Howarth
Carl,
这取决于你需要在每个控件中访问的内容。
>
所有控件都有一个基本类型System.Web.UI.HtmlControls.HtmlControl
所有其他控件都继承自。
如果你只需要访问基本控件属性,如:ClientId to
确定点击了哪个控件然后你可以转换任何HtmlControl像
转发器或表单元格到HtmlControl并访问那些基础
属性。如果您需要访问特定于该类型的属性
of control,那么您需要按照自己的方式进行投射。
-
此致,
S. Justin Gengo,MCP
网站开发人员/程序员
www.aboutfortunate.com
混乱无序。 ;
Nietzsche
" Carl Howarth" <钙********* @ discussions.microsoft.com>在留言中写道
新闻:A6 ********************************** @ microsof t.com ...
Carl,
It depends on what you need to access in each control.
All the controls have a base type System.Web.UI.HtmlControls.HtmlControl
which all the other controls inherit from.
If you only need to acces base control properties like: ClientId to
determine which control was clicked then you can cast any HtmlControl like
the repeater or the table cell to a HtmlControl and access those base
properties. If you need to access properties that are specific to that type
of control then you need to cast as you are doing.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Carl Howarth" <Ca*********@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com...
你好,
我目前正在使用我们的一些aspx.vb
文件'严格'' 。我有一个函数,当一个datarepeater绑定
或选择了datareader上的一个按钮时调用。该函数接受一个
''sender''对象,根据
函数的运行方式,该对象可能属于不同类型。
在一个实例中,类型为 System.Web.UI.WebControls.RepeaterItem"和
在其他人身上是System.Web.UI.HtmlControls.HtmlTableCell。我可以在以前简单地使用sender.FindControl,我现在必须检查
''sender.GetType.ToString''值,并使用if
获取每个控件基于此的陈述,所以我可以将我的发送者对象转换为正确的
类型。
这已经奏效,但我不能不觉得必须有一个更容易和
的整洁器
这样做的方式!
如果有人有任何建议他们会感激不尽。
非常感谢,
Carl Howarth
Hello there,
I am currently in the process of ''getting strict'' with some of our aspx.vb
files. I have a function that is called either when a datarepeater is
bound
or when a button on the datareader is selected. The function accepts a
''sender'' object, which may be of a different type depending on how the
function is ran.
In one instance the type is "System.Web.UI.WebControls.RepeaterItem", and
on
others it is "System.Web.UI.HtmlControls.HtmlTableCell". Where i could
simply
use sender.FindControl previously, I now have to check the
''sender.GetType.ToString'' value and get each of the controls using if
statements based on this so I can cast my sender object to the correct
type.
This has worked but I can''t help feeling there must be an easier and
neater
way of doing this!
If anybody has any suggestions they''d be gratefully received.
Thanks very much,
Carl Howarth
我参加了Tech Ed 2003的一次会议,在那里每个人都被告知对于DirectCast非常感兴趣。在引擎盖下CType做了很多事情保护你的代码和DirectCast会导致问题。
-
真诚,
S. Justin Gengo,MCP
网站开发人员/程序员
www.aboutfortunate.com
混乱无序。
Nietzsche
Mr Newbie <他** @ now.com>在消息中写道
新闻:eW ************** @ TK2MSFTNGP12.phx.gbl ...
I attended a conference at Tech Ed 2003 where everyone was told to be very
leery of DirectCast. Under the hood CType does a lot of things that protect
your code and DirectCast can cause problems.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Mr Newbie" <he**@now.com> wrote in message
news:eW**************@TK2MSFTNGP12.phx.gbl...
没有。你正在走上正轨。您可能希望更快地使用DirectCast作为其中的其他内容。
-
最好的问候
独特的Mr Newbie o?o
" Carl Howarth" <钙********* @ discussions.microsoft.com>在消息中写道
新闻:A6 ********************************** @ microsof t.com。 ..
Nope. You are on track. You may want to use DirectCast instead as its
faster amongst other things.
--
Best Regards
The Inimitable Mr Newbie o?o
"Carl Howarth" <Ca*********@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com...
你好,
我目前正在使用我们的一些
aspx.vb
文件'严格'' 。我有一个函数,当一个datarepeater绑定
或选择了datareader上的一个按钮时调用。该函数接受一个
''sender''对象,根据
函数的运行方式,该对象可能属于不同类型。
在一个实例中,类型为 System.Web.UI.WebControls.RepeaterItem"和
在其他人身上是System.Web.UI.HtmlControls.HtmlTableCell。我可以在以前简单地使用sender.FindControl,我现在必须检查
''sender.GetType.ToString''值,并使用if
获取每个控件基于此的陈述,所以我可以将我的发送者对象转换为正确的
类型。
这已经奏效,但我不能不觉得必须有一个更容易和
的整洁器
这样做的方式!
如果有人有任何建议他们会感激不尽。
非常感谢,
Carl Howarth
Hello there,
I am currently in the process of ''getting strict'' with some of our
aspx.vb
files. I have a function that is called either when a datarepeater is
bound
or when a button on the datareader is selected. The function accepts a
''sender'' object, which may be of a different type depending on how the
function is ran.
In one instance the type is "System.Web.UI.WebControls.RepeaterItem", and
on
others it is "System.Web.UI.HtmlControls.HtmlTableCell". Where i could
simply
use sender.FindControl previously, I now have to check the
''sender.GetType.ToString'' value and get each of the controls using if
statements based on this so I can cast my sender object to the correct
type.
This has worked but I can''t help feeling there must be an easier and
neater
way of doing this!
If anybody has any suggestions they''d be gratefully received.
Thanks very much,
Carl Howarth
这篇关于选项严格使用Ctype(发件人....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!