So that the bind of onserverclick
work it needs to be declared physically in your aspx. This is because in the render event and before the Page_load
ASP.Net will parse your content and replace your onserverclick='deleteRow'
by a javascript call responsible for PostBack
to the server, in the click
of the element.
See the example below where the control was added to Default.aspx
:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication.Form._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<button id='lbotao' type='submit' runat='server' onserverclick='deleteRow' class='btn btn-light float-right'><i class='fas fa-trash-alt'></i>teste</button>
</asp:Content>
Now see how the component is rendered in the browser:
<button onclick="__doPostBack('ctl00$MainContent$lbotao','')" id="MainContent_lbotao" type="submit" class="btn btn-light float-right"><i class="fas fa-trash-alt"></i></button>
As you are adding control as an html string this conversion will not be performed and you will end up with a simple transcription of what you declared.
<button id="lbotao" type="submit" runat="server" onserverclick="deleteRow" class="btn btn-light float-right"><i class="fas fa-trash-alt"></i></button>
Make the event public:
public void deleteRow(object sender, EventArgs e)
– Augusto Vasques
Still no running event
– Afonso
Try prefixing the button:
<asp:button
.... It’s only a two-point– Augusto Vasques
Did not solve, I tried to change the name of the event and also still does not work
– Afonso
Just to test, passes the event to Onclick.
– Augusto Vasques
It didn’t, I don’t understand why it didn’t run Vent, supposedly it’s all for Vent to run properly.
– Afonso
Let’s go continue this discussion in chat.
– Afonso