Greetings mates,
Things have changed greatly on this forum since the last time I was here which seems like a century ago.
Anyway, hopefully, some would be kind enough to assist with this.
We have an app that has run perfectly since 2018 until we made a minor change.
This is an app that allows user to dynamically add a new row as needed.
As stated, worked perfectly until we were recently instructed to create a DropdownList that dynamically displays or hides some controls based on selection from the DropdownList.
The issue we are currently having is that each time you click a button to add a new row, though the new row gets created but the mouse quickly jumps and focuses on the dropdown.
You will have to scroll back down to the section you added a new row.
Is there some changes I need to make to ensure that when a user clicks a button to add a new row, the mouse stays focused on that new row created?
Here is a slimmed down version of my code. The DropDownList is outside the GridView control,
Thanks a lot in advance for your help.
Things have changed greatly on this forum since the last time I was here which seems like a century ago.
Anyway, hopefully, some would be kind enough to assist with this.
We have an app that has run perfectly since 2018 until we made a minor change.
This is an app that allows user to dynamically add a new row as needed.
As stated, worked perfectly until we were recently instructed to create a DropdownList that dynamically displays or hides some controls based on selection from the DropdownList.
The issue we are currently having is that each time you click a button to add a new row, though the new row gets created but the mouse quickly jumps and focuses on the dropdown.
You will have to scroll back down to the section you added a new row.
Is there some changes I need to make to ensure that when a user clicks a button to add a new row, the mouse stays focused on that new row created?
Here is a slimmed down version of my code. The DropDownList is outside the GridView control,
Thanks a lot in advance for your help.
Code:
<asp:DropDownList ID="ddlChoice" AutoPostBack="true" style="background-color:#0093B2;border: 2px solid #92b200;width:310px;color:white;border-width:5px;" runat="server" class="form-control select2-selection select2-selection--single form-control input-lg" role="combobox" aria-haspopup="true" aria-expanded="false" aria-labelledby="select2-e8ez-container" OnSelectedIndexChanged="ddlChoice_Changed">
<asp:ListItem Text="Please select >>" Value="" />
<asp:ListItem Text="I want to use my ID Card" Value="CardNo" />
<asp:ListItem Text="I want to use my SS number" Value="SSNo" />
</asp:DropDownList><br />
<asp:RequiredFieldValidator ID="rfvDDL" runat="server"
ControlToValidate="ddlChoice"
Display="Dynamic"
ErrorMessage="Please make your selection."
InitialValue=""
ForeColor="Red" >
</asp:RequiredFieldValidator>
<div class="table-responsive">
<asp:gridview ID="Gridview1" RowStyle-Wrap="false" gridlines="None" runat="server" ShowFooter="true" AutoGenerateColumns="false" onrowdatabound="Gridview1_RowDataBound" OnRowDeleting="Gridview1_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Name">
<headerstyle horizontalalign="Left" />
<ItemTemplate>
<asp:TextBox ID="txtname" TabIndex="4" Text='<%# Eval("ename") %>' placeholder="Name...(e.g, ABC, Inc.)" runat="server" style="width:375px;" AutoPostBack="true" class="form-control textClass align-left" OnTextChanged="txtname_TextChanged"></asp:TextBox><br />
<asp:CheckBox ID="grid1Details" ClientIDMode="Static" runat="server" Checked="false" AutoPostBack="true" OnCheckedChanged="Grid1CheckChanged" /><span id="srcemp" runat="server" style="color:#ff0000">*Check this box if N/A</span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtaddress" TabIndex="5" Text='<%# Eval("address") %>' placeholder="Address..." runat="server" style="width:375px;" class="form-control textClass align-left" AutoPostBack="true" OnTextChanged="txtname_TextChanged"></asp:TextBox><br /><br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="ButtonAdd" runat="server" OnClientClick="BtnClick();" CausesValidation="true" Text="Add another row if needed"
onclick="ButtonAdd_Click" style="border: 1px solid #6E6E6E;font-family: 'Arial Unicode MS';background-color: #0093B2;color: #FFFFFF;font-size: 12pt;font-style: normal;text-align: center;padding-right: 10px;padding-left: 10px;" /><br /><br /><br>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="sourceDelete" runat="server" Text="Delete" CommandName="Delete"
style="border: 1px solid #6E6E6E;font-family: 'Arial Unicode MS';background-color: #0093B2;color: #FFFFFF;font-size: 12pt;font-style: normal;text-align: center;padding-right: 10px;padding-left: 10px;" OnClientClick="return confirm('Are you sure you want to remove this row?')" /> <br /><br /><br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
</div>
VB:
Protected Sub ddlChoice_Changed(ByVal sender As Object, ByVal e As EventArgs)
If ddlChoice.SelectedItem.Value = "CardNo" Then
pnlCardNo.Visible = True
pnlSSNO.Visible = False
Else
pnlCardNo.Visible = False
pnlSSNO.Visible = True
End If
End Sub
Protected Sub txtname_TextChanged(sender As Object, e As EventArgs)
For Each row As GridViewRow In Gridview1.Rows
Dim ename As TextBox = TryCast(row.FindControl("txtname"), TextBox)
Dim address As TextBox = TryCast(row.FindControl("txtaddress"), TextBox)
Dim sourceSelect As CheckBox = TryCast(row.FindControl("grid1Details"), CheckBox)
If ename.Text.Length > 0 AndAlso address.Text.Length > 0 Then sourceSelect.Enabled = False Else sourceSelect.Enabled = True
Next
End Sub
Code: