0 Replies - 339 Views - Last Post: 26 April 2019 - 11:14 AM Rate Topic: -----

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 602
  • View blog
  • Posts: 3,993
  • Joined: 12-January 10

how are onlick or onblur events added dynamically?

Posted 26 April 2019 - 11:14 AM

i have a form where events have to be added dynamically as the user presses a button

currently the 1st button adds ok but then very other button doesnt. so when you get 2 buttons showing and you press the add argument button on the last created button, it deletes the previous button. in the image you can see the 2nd button created after the 1st is clicked-- however when you click the second one, it deletes the row instead of adding a new one

initial created button
 Protected Sub txtReasonMinutes_OnTextChanged(sender As Object, e As EventArgs)
        Dim _reasonArguments As New LoadDropDowns
       
       
            Dim row As TableRow = New TableRow()
            Dim cell As TableCell = New TableCell()
            Dim cell2 As TableCell = New TableCell()
        Dim cell3 As TableCell = New TableCell()
            Dim ddlReasonD As DropDownList = new DropDownList()
            Dim newtextBox As TextBox = New TextBox()
        Dim _newBtn As Button = New Button()
            Dim rowIdNumber As integer = reasonsTable.Rows.Count()
            Dim rowIDName As string = "txtReasonMinutes"
            Dim rowDDLName As String = "ddlReason"
       
       
        ddlReasonD.DataSource =  _reasonArguments.LoadDropDowns("HR",0)
        ddlReasonD.DataTextField = "txtDTArgumentsName"
        ddlReasonD.DataValueField = "DowntimeArgumentsID"
        ddlReasonD.ID = rowDDLName + rowIdNumber.ToString()
        ddlReasonD.DataBind()
        cell.Controls.Add(ddlReasonD)
        row.Cells.add(cell)

        newtextBox.ID =  rowIDName + rowIdNumber.ToString()
        newtextBox.CssClass ="textboxStyle3"
        newtextBox.AutoPostBack = "True"
        'newtextBox.TextChanged +=  EventHandler(AddressOf me.txtReasonMinutes_OnTextChanged)
        'newtextBox.Attributes.Add("OnTextChanged","txtReasonMinutes_OnTextChanged")
        'AddHandler newtextBox.TextChanged, AddressOf Me.txtReasonMinutes_OnTextChanged
        cell2.Controls.add(newtextBox)
        row.Cells.add(cell2)


        _newBtn.Text = "Add Argument"
        _newBtn.CssClass = "BtnSmallStyle"
        AddHandler _newBtn.Click , AddressOf Me.btnNewReason_onclick  '"btnNewReason_onclick"
        cell3.controls.add(_newBtn)
        row.Cells.add(cell3)

        reasonsTable.Rows.Add(row)
      
        
    End Sub



vb code for buttons
 Sub btnNewReason_onclick(sender As Object, e As EventArgs)

        dim Button As Button = sender

        Dim _reasonArguments As New LoadDropDowns
       
       
        Dim row As TableRow = New TableRow()
        Dim cell As TableCell = New TableCell()
        Dim cell2 As TableCell = New TableCell()
        Dim cell3 As TableCell = New TableCell()
        Dim ddlReasonD As DropDownList = new DropDownList()
        Dim newtextBox As TextBox = New TextBox()
        Dim _newBtn As Button = New Button()
        Dim rowIdNumber As integer = reasonsTable.Rows.Count()
        Dim rowIDName As string = "txtReasonMinutes"
        Dim rowDDLName As String = "ddlReason"
       
       
        ddlReasonD.DataSource =  _reasonArguments.LoadDropDowns("HR",0)
        ddlReasonD.DataTextField = "txtDTArgumentsName"
        ddlReasonD.DataValueField = "DowntimeArgumentsID"
        ddlReasonD.ID = rowDDLName + rowIdNumber.ToString()
        ddlReasonD.DataBind()
        cell.Controls.Add(ddlReasonD)
        row.Cells.add(cell)

        newtextBox.ID =  rowIDName + rowIdNumber.ToString()
        newtextBox.CssClass ="textboxStyle3"
        cell2.Controls.add(newtextBox)
        row.Cells.add(cell2)

        _newBtn.Text = "Add Argument"
        _newBtn.CssClass = "BtnSmallStyle"
         AddHandler _newBtn.Click , AddressOf Me.btnNewReason_onclick '"btnNewReason_onclick"
        cell3.controls.add(_newBtn)
        row.Cells.add(cell3)

        reasonsTable.Rows.Add(row)
    End Sub




asp:

 <asp:Panel runat="server" GroupingText="DOWNTIME REASONS" class="panelReasons" >
                  <asp:Table Width="100%" runat="server" id="reasonsTable">
                      <asp:TableRow runat="server">
                          <asp:TableCell runat="server">
                             <asp:Label runat="server" text="Reason"></asp:Label>
                          </asp:TableCell>   
                          <asp:TableCell runat="server">       
                              <asp:Label runat="server" text="Minutes"></asp:Label>
                          </asp:TableCell>
                      </asp:TableRow>
                        <asp:TableRow runat="server">
                            <asp:TableCell runat="server">         
                                <asp:DropDownList runat="server" ID="ddlReason" />
                            </asp:TableCell>   
                            <asp:TableCell runat="server">       
                                <asp:TextBox ID="txtReasonMinutes" runat="server"  CssClass="textboxStyle3" OnTextChanged="txtReasonMinutes_OnTextChanged" AutoPostBack="True"></asp:TextBox>
                            </asp:TableCell>
                            <asp:TableCell runat="server">       
                                <asp:Button runat="server" ID="btnNewReason" onclick="btnNewReason_onclick" text="Add Argument" CssClass="BtnSmallStyle"/>
                            </asp:TableCell>
                        </asp:TableRow>
                  </asp:Table>
             </asp:Panel>

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Page 1 of 1