i have this button on my C# context:
<button id='Update' OnServerClick='UpdateCart'>Update</button>
now I wanna to pass parameter (num) to (UpdateCart) Method :
protected void UpdateCart(object sender, EventArgs e)
{
Response.Cookies["Cart"]["Qty(" + num + ")"] = Request.Form["Qty" + num];
}
How I can do that ?
You can use a lambda expression to pass multiple arguments to an onclick event.
Blazor does not have support to manipulate DOM elements directly, but we can still achieve it by using JavaScript interop. By creating a reference to an element, we can send it as a parameter to the JavaScript method via interop.
By using Blazor route parameters, you can pass values from one page to another page. Use NavigationManager to pass a value and route the parameter to another page. Follow this example to achieve passing values from one page to another. Get the passed Page1 parameter value in Page2.
Use ASP.NET Button control instead of <button/>
markup that allow you to set value via CommandArgument property and use Command event (do not use Click) to retrieve value of CommandArgument
property.
Markup:
<asp:Button
ID="Button1"
runat="server"
CommandArgument="10"
oncommand="Button1_Command"
Text="Button" />
Code:
protected void Button1_Command(object sender, CommandEventArgs e)
{
string value = e.CommandArgument.ToString();
}
You would use the 'commandArgument' attribute. Here's an example on the MSDN
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With