CType不适用于Button [英] CType not working for Button

查看:108
本文介绍了CType不适用于Button的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容:


sub submitQuestion_click(Sender as Object,e as EventArgs)

Dim submitButton as Button = CType(sender,Button)


这给我一个错误,上面写着:


" System.InvalidCastException:指定的强制转换无效。


为什么会这样?


发件人是一个按钮。


Tom

解决方案



" tshad" < TS ********** @ ftsolutions.com>在消息中写道

新闻:OB ************** @ TK2MSFTNGP14.phx.gbl ...

我有以下内容:

sub submitQuestion_click(发件人作为对象,e作为EventArgs)
将submitButton变暗为Button = CType(发件人,按钮)

这给我一个错误说:

System.InvalidCastException:指定的强制转换无效。

为什么?

发件人是一个按钮。

Tom




尝试这个,如果你仍然无法弄明白,发布结果...

Sub submitQuestion_Click(ByVal Sender As Object,ByVal e As EventArgs)

Response.Write(Sender.GetType()。ToString())

End Sub


然后运行应用程序并单击按钮。


如果这没有用,请记得发布打印的内容。


Mythran


试试这个:


Dim submitButton = CType(发件人,按钮)

Jason Bentley


" Mythran" <き******** @ hotmail.comREMOVETRAIL>在消息中写道

news:e5 ************** @ TK2MSFTNGP14.phx.gbl ...


" ; tshad" < TS ********** @ ftsolutions.com>在消息中写道
新闻:OB ************** @ TK2MSFTNGP14.phx.gbl ...

我有以下内容:

sub submitQuestion_click(发件人作为对象,e作为EventArgs)
将submitButton作为Button = CType(发件人,按钮)昏暗

这给了我一个错误说:

System.InvalidCastException:指定的强制转换无效。

为什么会这样?

发件人是一个按钮。

Tom

尝试这个,如果你还是无法弄清楚,发布结果......

Sub submitQuestion_Click(ByVal Sender As Object,ByVal e As EventArgs)
Response.Write(Sender.GetType()。ToString ())
End Sub

然后运行应用程序并单击按钮。

如果这没有帮助,请记得发布打印的内容。




我做到了并得到了结果:


sender type = System.Web.UI.WebControls.Button


Tom
Mythran



I have the following:

sub submitQuestion_click(Sender as Object, e as EventArgs)
Dim submitButton as Button = CType(sender,Button)

This gives me an error that says:

" System.InvalidCastException: Specified cast is not valid. "

Why is that?

Sender is a button.

Tom

解决方案


"tshad" <ts**********@ftsolutions.com> wrote in message
news:OB**************@TK2MSFTNGP14.phx.gbl...

I have the following:

sub submitQuestion_click(Sender as Object, e as EventArgs)
Dim submitButton as Button = CType(sender,Button)

This gives me an error that says:

" System.InvalidCastException: Specified cast is not valid. "

Why is that?

Sender is a button.

Tom



Try this and if you still can''t figure it out, post the results...

Sub submitQuestion_Click(ByVal Sender As Object, ByVal e As EventArgs)
Response.Write(Sender.GetType().ToString())
End Sub

Then run the application and click the button.

If this doesn''t help, remember to post what is printed.

Mythran


Try this:

Dim submitButton = CType(sender, Button)
Jason Bentley


"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...


"tshad" <ts**********@ftsolutions.com> wrote in message
news:OB**************@TK2MSFTNGP14.phx.gbl...

I have the following:

sub submitQuestion_click(Sender as Object, e as EventArgs)
Dim submitButton as Button = CType(sender,Button)

This gives me an error that says:

" System.InvalidCastException: Specified cast is not valid. "

Why is that?

Sender is a button.

Tom

Try this and if you still can''t figure it out, post the results...

Sub submitQuestion_Click(ByVal Sender As Object, ByVal e As EventArgs)
Response.Write(Sender.GetType().ToString())
End Sub

Then run the application and click the button.

If this doesn''t help, remember to post what is printed.



I did that and got the result:

sender type = System.Web.UI.WebControls.Button

Tom
Mythran



这篇关于CType不适用于Button的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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