简体   繁体   中英

pass parameters with OnServerClick vb.net

I am really new in VB and It is hard to get my head around it especially working with non-MVC projects, so i wish i can find my answer here.

I want to pass arguments with the OnServerClick the code below is the html code:

<a id="Anchor1" OnServerClick="LogIn" runat=server> Click Me </a>

and the method in the server is below:

 Protected Sub LogIn(sender As Object, e As EventArgs)
   e.value
   End Sub

I want to pass parameters(args) to the LogIn method??

I don't want to use any VB or razor buttons or anchor tags i want to use the html tags with the onserverclick attribute. is that possible??

thank you in advance.

You can add custom attribute to aspx <a> like this.

<a id="Anchor1" OnServerClick="LogIn" runat="server" customdata="hello"> Click Me </a>

And get that value in LogIn .

Protected Sub LogIn(sender As Object, e As EventArgs)
    Dim myButton = CType(sender, HtmlAnchor)
    Dim valuepassedfromUI = myButton.Attributes("customdata")
    Dim buttonID = myButton.ClientID
End Sub

, See the screenshot.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM