c# html hyperlink call a method
17,111
<a ID="MyAnchor"
OnServerClick="menuPersonTab_OnMenuItemClick"
runat="server"> Click This </a>
Here is an explained example from MSDN.
Author by
gdubs
Updated on June 04, 2022Comments
-
gdubs almost 2 years
is it possible to call a method using a regular hyperlink like so:
<div class="menu"> <ul> <li><a href=#> click this </a></li> <li><a href=#> click this again </a></li> </ul> <div>
call this method:
protected void menuPersonTab_OnMenuItemClick(object sender, MenuEventArgs e) { mvPerson.ActiveViewIndex = Int32.Parse(menuPersonTab.SelectedValue); }
no? yes?
-
gdubs about 13 yearsit gives me a > Compiler Error Message: CS1026: ) expected
-
gdubs about 13 yearsthis gives me a CS1501: No overload for method 'menuPersonTab_OnMenuItemClick' takes 0 arguments
-
yogsma about 13 yearsDid you try using = instead of #?
-
Anton about 13 yearsIf you are not able to attach server side event to code(for example - HTML code is creating by Javascript) but you need to call server event - you can call javascript function __doPostBack with needed parameters. __doPostBack will post back data to server where you can process it and call necessary function.
-
Anton about 13 yearsCreate "protected void menuPersonTab_OnMenuItemClick()" function with 0 arguments
-
Yuriy Faktorovich about 13 yearsThat method is a void and I don't think gdubs meant to output anything inside the href from the method.