开发者

VB.Net Calling vb Sub/Function from a string/label?

In my VB code behind the aspx is it possible for me to call a function based upon a click on a string format.

e.g.

Sub testSub()
Do Nothing
End Sub

Dim test1 as string = string.format("hyperlink href blah blah", Hello)
Dim test2 as string = string.format("Call my test sub here?", World)
Dim stringtoUse as string = String.Format(test1, test2)

Then add my stringtoUse to my control. So that on my control I have two words Hello which when clicked goes to my hyperlink and World which when clicked calls my function/sub.

Any information or adv开发者_StackOverflow中文版ice on how to approach this would be great.

Thanks Guys!


If I am understanding your problem correctly, you want to be able to set the text from your code behind and have two different actions based on which half is clicked?

The most straightforward manner wold be to create two controls and set the text separately.

<asp:HyperLink id="hpMyLink" runat="Server" ...etc.  >
<asp:LinkButton id="lbMyLinkButton" runat="server" ..etc>

Then set the values from your page load (or wherever):

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   hpMyLink.Text = string.format("hyperlink href blah blah", Hello)
   lbMyLinkButton.Text = string.format("Call my test sub here?", World)
End Sub

Then set your href for the first and handle the Click event for the second.

technically it would be possible to make a single link go two places, but it would require a great deal of trickery, would not work in some circumstances, and I can't imagine it would give you anything more than what you get from having two separate controls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜