简体   繁体   中英

html button text not changing when gridview OnSelectedIndexChanged fired

After clicking the edit button of gridview btnSaveClass.text text change as expected but on the other hand btnSave.text text not changing

I have debugged certain portion of the code. And find that it's taking the changed text btnSave.InnerText = "Update"; in this line. But some how it loose the data. And some how it becomes same as it was.

//==========================================================This is The Markup=============================

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="col-md-4 col-sm-4 col-xs-12 form-group item margin">
<input type="text" class="form-control  has-feedback-left" id="txtFName" maxlength="20" onkeypress="return isNameKey(event,this)" required="required" runat="server" placeholder="First Name" />



<span class="fa fa-user  form-control-feedback left" aria-hidden="true"></span>
</div>

<div class="col-md-4 col-sm-4 col-xs-12 form-group item margin">
<input type="text" class="form-control  has-feedback-left" id="txtLName" onkeypress="return isNameKey(event,this)" required="required" runat="server" maxlength="20" placeholder="Last Name" />
<span class="fa fa-user form-control-feedback left" aria-hidden="true"></span>
</div>
<div class="col-md-4 col-sm-4 col-xs-12 form-group item margin">
<input type="text" class="form-control  has-feedback-left" id="txtConNumber" onkeypress="return isNumberKey(event,this)" maxlength="11" required="required" runat="server" placeholder="Contact Number" />
<span class="fa fa-mobile form-control-feedback left" aria-hidden="true"></span>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<div class="ln_solid"></div>
<div class="form-group ">
<div class="col-md-6 margin ">
                                   //===================================================This button text not changing======================  
<button type="button" id="btnSave" runat="server" class="btn btn-success" onserverclick="btnSaveOnClick">Save</button>
<button id="Button2" runat="server" type="button" class="btn btn-primary" onserverclick="btnRefreshOnClick">Refresh</button>

</div>
</div>
<div class="col-md-3 col-sm-3 col-xs-12 form-group item">
<asp:TextBox ID="txtRegInfo" required="required" CssClass="form-control has-feedback-left" placeholder="Student Official Id" MaxLength="50" runat="server"></asp:TextBox>

<span class="fa fa-registered form-control-feedback left" aria-hidden="true"></span>
</div>

<div class="col-md-3 col-sm-3 col-xs-12 form-group item " style="position: relative;">
<asp:UpdatePanel ID="UpdatePa" runat="server">
<ContentTemplate>
<div class="col-md-12 col-sm-12 col-xs-12 form-group item" style="margin: 0px; padding: 0px;" id="DivddlClassName" runat="server">
<asp:DropDownList ID="ddlClassName" runat="server" CssClass="col-md-12 form-control item has-feedback-left" AutoPostBack="true" OnSelectedIndexChanged="ddlClassNameOnSelectedIndexChanged">
</asp:DropDownList>

<span class="fa fa-tasks form-control-feedback left" aria-hidden="true"></span>
</div>

</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="col-md-3 col-sm-3 col-xs-12 form-group item">
<asp:TextBox ID="txtClassRoll" required="required" onkeypress="return isNumberKey(event,this)" MaxLength="5" CssClass="form-control has-feedback-left" placeholder="Class Roll" runat="server"></asp:TextBox>

<span class="fa fa-star form-control-feedback left" aria-hidden="true"></span>
</div>
<div class="col-md-3 col-sm-3 col-xs-12 form-group item">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<div class="col-md-12 col-sm-12 col-xs-12 form-group item" style="margin: 0px; padding: 0px;" id="ddlSectionDiv" runat="server">
<asp:DropDownList ID="ddlSection" runat="server" CssClass="col-md-12 form-control item has-feedback-left" AutoPostBack="true">
<asp:ListItem Value="0" Text="Select A Section"></asp:ListItem>
<asp:ListItem Value="1" Text="A"></asp:ListItem>
<asp:ListItem Value="2" Text="B"></asp:ListItem>
<asp:ListItem Value="3" Text="C"></asp:ListItem>
<asp:ListItem Value="4" Text="D"></asp:ListItem>
<asp:ListItem Value="5" Text="E"></asp:ListItem>
<asp:ListItem Value="6" Text="F"></asp:ListItem>
</asp:DropDownList>

<span class="fa fa-list-alt form-control-feedback left" aria-hidden="true"></span>
</div>
</ContentTemplate>
</asp:UpdatePanel>

</div>
<div class="clearfix"></div>
<div class="col-md-3 col-sm-3 col-xs-12 form-group item">
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<div class="col-md-12 col-sm-12 col-xs-12 form-group item" style="margin: 0px; padding: 0px;" id="ddlShiftNameDiv" runat="server">
<asp:DropDownList ID="ddlShiftName" runat="server" CssClass="col-md-12 form-control item has-feedback-left" AutoPostBack="true">
<asp:ListItem Value="0" Text="Select A Shift"></asp:ListItem>
<asp:ListItem Value="1" Text="Morning"></asp:ListItem>
<asp:ListItem Value="2" Text="Day"></asp:ListItem>
<asp:ListItem Value="3" Text="Evening"></asp:ListItem>
</asp:DropDownList>
<span class="fa fa-list-alt form-control-feedback left" aria-hidden="true"></span>
</div>
</ContentTemplate>
</asp:UpdatePanel>



<div class="form-group ">
<div class="col-md-6 ">
//==========================================================================This button text changed as expected==============================================
<button type="button" data-target="#myModal" class="btn btn-success" id="btnSaveClass" runat="server" onserverclick="btnSaveClassInfoOnClick">Save</button>
<button id="btn" runat="server" type="button" class="btn btn-primary" onserverclick="btnRefreshOnClick">Refresh</button>
</div>
</div>



//========================================================================This is the gridview===============================
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<div class="col-md-12 text-center" style="padding: 10px; background-color: red; color: white; font-weight: bold" id="lblMsg" runat="server" visible="false">One Row has Deleted</div>
<asp:GridView ID="GvStudentIformation" runat="server" Width="100%" CssClass="table table-striped table-bordered table-hover jambo_table bulk_action"
AutoGenerateColumns="False" DataKeyNames="StdntID" AllowPaging="True" OnPageIndexChanging="GvStudentIformationOnPageIndexChanged"
                                            OnRowDeleting="GvStudentInfoOnRowDeleting" OnSelectedIndexChanged="GvStudentInfoOnSelectedIndexChanged">
<HeaderStyle HorizontalAlign="Center" ForeColor="White" BackColor="#3F5367"></HeaderStyle>
<RowStyle CssClass="even pointer " HorizontalAlign="Center" BackColor="#E9F4F2"></RowStyle>
<Columns>
<asp:BoundField DataField="RegistrationNo" ItemStyle-HorizontalAlign="Center" HeaderText="Registration No"></asp:BoundField>
<asp:BoundField DataField="FullName" ItemStyle-HorizontalAlign="Center" HeaderText="Name"></asp:BoundField>
<asp:BoundField DataField="StdntID" HeaderText="Student Class Id">
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:BoundField DataField="FirstName" HeaderText="First Name">
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:BoundField DataField="LastName" HeaderText="Last Name">
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:BoundField DataField="StdntClassID" HeaderText="Student Class Id">
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="ButtonDelete" runat="server" CausesValidation="False" CommandName="Delete"><img src="../../images/delete.png" /></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowSelectButton="true" ButtonType="Image" SelectImageUrl="~/images/Edit.png" ItemStyle-Height="5px" ItemStyle-HorizontalAlign="Center"></asp:CommandField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Details">
<ItemTemplate>
<asp:HyperLink ID="btnDetails" runat="server" CausesValidation="False" ForeColor="black" NavigateUrl='<%# String.Format("../Admission/StudentDetails.aspx?StdntID={0}&StdntClassID={1}", Eval("StdntID"), Eval("StdntClassID")) %>'><i class="fa fa-eye"></i> Details</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<SelectedRowStyle BackColor="#CFF0E9" Font-Bold="True" ForeColor="#333333" BorderColor="#1ABC9C" />
<HeaderStyle BackColor="#3F5367" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="white" />
<PagerStyle HorizontalAlign="Left" ForeColor="#3F5367" CssClass="gvPagers pad" />
<PagerSettings Mode="NumericFirstLast" PageButtonCount="4" FirstPageText="First" LastPageText="Last" />
<EmptyDataTemplate>
<div class="text-center">No records found.</div>
</EmptyDataTemplate>
</asp:GridView>
<asp:HiddenField ID="HdfstdId" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>

//===========Here is the problem, First button  text not changing but Second Button Text Changes as Expected=================
protected void GvStudentInfoOnSelectedIndexChanged(object sender, EventArgs e)
{
string id = GvStudentIformation.SelectedRow.Cells[0].Text.Trim().Replace("&nbsp;", "");
HdfstdId.Value = id;
txtFName.Value = GvStudentIformation.SelectedRow.Cells[3].Text.Trim().Replace("&nbsp;", "");
txtLName.Value = GvStudentIformation.SelectedRow.Cells[4].Text.Trim().Replace("&nbsp;", "");
btnSave.InnerText = "Update";
btnSaveClass.InnerText = "Update";
} 

Exactly I used script for changing button Text. And that solved the issue.

function ButtonTextChange() {
                document.getElementById('<%=btnInfoSave.ClientID %>').innerText = "Update";
            }   

Here I call The funtion.

   ScriptManager.RegisterStartupScript(this, this.GetType(), "CallMyFunction", "ButtonTextChange();", true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM