Jump to content
Sign in to follow this  
rhishi20

why there is need of explicit type casting while getting value from sender of linkbutton

Recommended Posts

case1
--------
Protected Sub lnkResdept_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim resdept As String
resdept = sender.text
End Sub
case2
--------
Protected Sub lnkResdept_Click(ByVal sender As Object, ByVal e As System.EventArgs)
resdept= CType(sender, LinkButton).Text
end sub
I am not able to understand difference between these two cases, case1 produces the linkbutton's value for example C1500017 and case2 also produces same result. I am not able to understand why explicit type casting is done in case2.
thanks,
Rhishikesh

Share this post


Link to post
Share on other sites

It's just 2 ways to do the same thing. You can either access the text property, or you can convert the sender object to a Text type (which probably accesses the text property behind the scenes).

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...