1

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";
} 

Priom
  • 23
  • 8
  • Some questions: does the code belong to the same page? Why in the first piece of code you are not using webforms? there are too many UpdatePanel. Have you tried to use only one panel or remove them? – Emanuele Jun 19 '19 at 09:57
  • All are in the same page. Yes, I have tried 1 update panel . But that causing problem for modal.That's why i have to use too many. – Priom Jun 19 '19 at 09:59
  • For keeping design perfect as template I have used html controls. And I have tried removing UpdatePanel also.But some short of reason ```btnSave.InnerText``` not changing. But second one worked as expected. – Priom Jun 19 '19 at 10:09
  • Maybe you initialize btnSave.InnerText else where in the c# code? – Emanuele Jun 19 '19 at 10:10
  • That's also I have checked. I only initialize that in ```clear()``` function. But I yet not use it. And also one thing, I have added another button on that portion for testing. But that's text also not changing. – Priom Jun 19 '19 at 10:15
  • This last button is also in clear() function? – Emanuele Jun 19 '19 at 10:19
  • No, That's not in ```clear()``` – Priom Jun 19 '19 at 10:21
  • Have txtFName, txtLName right values? – Emanuele Jun 19 '19 at 10:26
  • Yes, On Code that are right values. But while customizing the question I forgot to change cell no. – Priom Jun 19 '19 at 10:28
  • I have solved the text change issue by putting that button within the ```UpdatePanel``` But Now new issue come. Click event not working. – Priom Jun 19 '19 at 11:39
  • It's better to avoid UpdatePanel. https://stackoverflow.com/questions/25075538/button-click-not-working-inside-update-panel – Emanuele Jun 19 '19 at 11:45
  • I have tried that before informing you. But that's also not working.I have checked validation also and also changed button to ```LinkButton``` . But the thing is nothing worked for me. – Priom Jun 19 '19 at 11:49
  • Problem solved. – Priom Jun 20 '19 at 04:09
  • Can you edit your post adding the solution? @Priom – Emanuele Jun 20 '19 at 07:55
  • Yes, Though I use script for changing button text. @Emanuele – Priom Jun 22 '19 at 11:01

1 Answers1

0

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);
Priom
  • 23
  • 8