Show modal by item ID in ASP.NET WebForms - c#

I'm using repeaters to display a list of items retrieved from the database. I would like to support basic CRUD operations on such items via a simple modal dialog box.
I have tried using onitemcommand to manipulate each item, I tried using labels to get id, I have also tried using OnClick on the buttons, with no luck.
Here it is the code for my repeater:
<div class="container-fluid">
<div class="row justify-content-left card-group">
<asp:Repeater ID="DataList1" runat="server" onitemcommand="DataList1_ItemCommand">
<ItemTemplate>
<div class="col-md-4 " style="margin-bottom: 1em;">
<%--A loop through the records in database--%>
<div class="card border-light mb-4 ">
<div class="card-content " >
<div class="card-header ">
<h4 class="my-0 font-weight-normal">
<asp:label ID="nameTage" style="font-size:16px;color:steelblue;" Text= '<%# Eval("ProjectName") %>' runat="server"/>
<asp:label ID="pID" Text='<%# DataBinder.Eval(Container.DataItem,"ProjectID") %>' runat="server" Visible="false"/>
</h4>
</div>
<div class="card-body ">
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<h6 class="card-text" style="font-size:10px; color:#a51313">
<span class="Text" > <%--The project description goes here--%>
<%-- <%= myItem["ProjDescription"].ToString() %>--%>
<%# Eval("ProjDescription") %>
</span>
</h6>
</div>
</div>
</div>
<div class="card-footer ">
<%--These are not for the submit buttons, they are for the models--%>
<%--Get the ID of the Project--%>
<%--<div class="btn-toolbar pull-right" id="buttonID" role="group" aria-label="Basic example" style="font-size:9px; color:white; align-content:center" runat="server">--%>
<asp:LinkButton type="button" ID="btn_details" class="btn btn-success btn-sm m-1" aria-pressed="true" data-toggle="modal" data-target="#detailsModal" runat="server" OnClick="IDButton1_Click" CausesValidation="false" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"ProjectID") %>' CommandName="Details" Text="Details"></asp:LinkButton>
<asp:LinkButton type="button" ID="btn_edit" class="btn btn-success btn-sm m-1" aria-pressed="true" data-toggle="modal" data-target="#editModal" runat="server" CausesValidation="false" CommandArgument='<%# Eval("ProjectID") %>' CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton type="button" ID="btn_delete" class="btn btn-success btn-sm m-1" aria-pressed="true" data-toggle="modal" data-target="#deleteModal" runat="server" CausesValidation="false" CommandArgument='<%# Eval("ProjectID") %>' CommandName="Delete" Text="Delete"></asp:LinkButton>
<%--</div>--%>
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
<%-- <% } %>--%>
</div>
</div>
'''
<!-- Modal for Details -->
<%--Get the ID of the Project--%>
<div class="modal fade" id="detailsModal" tabindex="-1" role="dialog" aria-labelledby="detailsModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="detailsModalLabel">Mission Project</h5>
<%--project.Name--%>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-horizontal col-8">
<div class="form-group row">
<asp:label Text="Project Title:" class="control-label" runat="server"/>
<asp:TextBox ID="TB1" Text="" runat="server" class="form-control" ReadOnly="true"></asp:TextBox>
</div>
<div class="form-group row">
<asp:label Text="Project Description:" class="control-label" runat="server"/>
<asp:TextBox ID="TB2" runat="server" class="form-control" rows="4" TextMode="multiline" ReadOnly="true"></asp:TextBox>
</div>
<div class="form-group row">
<asp:label Text="Department:" class="control-label" runat="server"/>
<asp:TextBox ID="TB3" runat="server" class="form-control" ReadOnly="true"></asp:TextBox>
</div>
<div class="form-group row">
<asp:label ID="HEreThere" Text="Contact Name:" class="control-label" runat="server"/>
<asp:TextBox ID="TB4" runat="server" class="form-control" ReadOnly="true"></asp:TextBox>
</div>
<div class="form-group row">
<asp:label Text="Launch Date:" class="control-label" runat="server"/>
<asp:TextBox ID="TB5" runat="server" class="form-control" ReadOnly="true"></asp:TextBox>
</div>
<div class="form-group row">
<asp:label Text="Note:" class="control-label" runat="server"/>
<asp:TextBox ID="TB6" runat="server" class="form-control" rows="7" TextMode="multiline" ReadOnly="true"></asp:TextBox>
</div>
<div class="form-group row">
<asp:label Text="Project Status:" class="control-label" runat="server"/>
<asp:TextBox ID="TB7" runat="server" class="form-control" ReadOnly="true"></asp:TextBox>
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button type="button" class="btn btn-secondary" data-dismiss="modal" runat="server" Text="Close" />
</div>
</div>
</div>
</div>
protected void Page_Load(object sender, EventArgs e)
{
lblMessage.Text = "";
//data = "";
if (!IsPostBack)
{
}
DataList1.DataSource = GetProjects();
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandArgument != null)
{
if (e.CommandName.Equals("Details"))
{
//int MissID = Convert.ToInt32(e.CommandArgument.ToString());
//lblMessage.Text = MissID.ToString
((Label)e.Item.FindControl("pID")).Visible = true;
}
else if (e.CommandName.Equals("Edit"))
{
((Label)e.Item.FindControl("pID")).Visible = true;
}
else if (e.CommandName.Equals("Delete"))
{
((Label)e.Item.FindControl("pID")).Visible = true;
}
}
// Label label = e.Item.FindControl("pID") as Label;
}
protected void IDButton1_Click(object sender, EventArgs e)
{
RepeaterItem item = (sender as LinkButton).Parent as RepeaterItem;
int MissID = Convert.ToInt32((item.FindControl("pID") as Label).Text);
(item.FindControl("pID") as Label).Visible = true;
// get command argument here
// int MissID = Convert.ToInt32(((sender as Button).NamingContainer.FindControl("pID") as Label).Text);
// lblMessage.Text = MissID.ToString();
DataSet dsID = GetProjectByID(MissID);
this.TB1.Text = dsID.Tables[0].Rows[0]["ProjectName"].ToString();
this.TB2.Text = dsID.Tables[0].Rows[0]["ProjDescription"].ToString();
this.TB3.Text = dsID.Tables[0].Rows[0]["Department"].ToString();
this.TB4.Text = dsID.Tables[0].Rows[0]["ContactName"].ToString();
this.TB5.Text = dsID.Tables[0].Rows[0]["DueDate"].ToString();
this.TB6.Text = dsID.Tables[0].Rows[0]["Notes"].ToString();
this.TB7.Text = GetStatusText(dsID.Tables[0].Rows[0]["StatusID"].ToString());
}

Because you don't have your Repeater binding wrapped in the check for PostBack, it is rebinding anytime a button event occurs. This essentially undos the changes you make in the click event. Wrapping it in the postback check should resolve the issue.
if (!IsPostBack)
{
DataList1.DataSource = GetProjects();
DataList1.DataBind();
}

Related

ASP.Net Button OnClick not firing up without setting UseSubmitBehavior="false"

Good evening guys, I would like to get some help with my code, the onclick event in my register button won't fire up if I have a modal in my masterpage, but If I remove it, it works. Any suggestion on what should I do? Here is my code
<div class="container mt-5 mb-5">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card">
<header class="card-header">
Log in
<h4 class="card-title mt-2">Sign up</h4>
</header>
<article class="card-body">
<div class="form-row mt-3">
<div class="col form-group">
<asp:Label ID="lblLastname" CssClass="col-form-label" runat="server" Text="Lastname:"></asp:Label>
<asp:TextBox ID="txtLastname" CssClass="form-control" runat="server" MaxLength="30" required="required"></asp:TextBox>
</div>
<div class="col form-group">
<asp:Label ID="lblFirstname" CssClass="col-form-label" runat="server" Text="Firstname:"></asp:Label>
<asp:TextBox ID="txtFirstname" CssClass="form-control" runat="server" MaxLength="30" required="required"></asp:TextBox>
</div>
</div>
<div class="form-row mt-3">
<div class="col form-group">
<asp:Label ID="lblUsername" CssClass="col-form-label" runat="server" Text="Username:"></asp:Label>
<asp:TextBox ID="txtUsername" CssClass="form-control" runat="server" MaxLength="40" required="required"></asp:TextBox>
</div>
<div class="col form-group">
<asp:Label ID="lblPassword" CssClass="col-form-label" runat="server" Text="Password:"></asp:Label>
<asp:TextBox ID="txtPassword" CssClass="form-control" runat="server" TextMode="Password" required="required"></asp:TextBox>
</div>
</div>
<div class="form-row mt-3">
<div class="col form-group">
<asp:Label ID="lblEmail" CssClass="col-form-label" runat="server" Text="Email:"></asp:Label>
<asp:TextBox ID="txtEmail" type="email" CssClass="form-control" runat="server" MaxLength="50" required="required"></asp:TextBox>
</div>
<div class="col form-group">
<asp:Label ID="lblPhoneNumber" CssClass="col-form-label" runat="server" Text="Phone Number:"></asp:Label>
<asp:TextBox ID="txtPhoneNumber" CssClass="form-control" runat="server" MaxLength="11" required="required"></asp:TextBox>
</div>
</div>
<div class="form-row mt-3">
<div class="col form-group">
<asp:Label ID="lblGender" CssClass="col-form-label" runat="server" Text="Gender:"></asp:Label>
<asp:DropDownList ID="ddlGender" CssClass="form-control" runat="server">
<asp:ListItem Value="0">Please select your gender</asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
</div>
<div class="col form-group">
<asp:Label ID="lblBirthdate" CssClass="col-form-label" runat="server" Text="Birth Date:"></asp:Label>
<asp:TextBox ID="txtBirthdate" type="date" CssClass="form-control" runat="server" required="required"></asp:TextBox>
</div>
</div>
<div class="form-row mt-4">
<div class="col form-group">
<asp:Button ID="btnClear" CssClass="btn btn-danger btn-block" runat="server" CausesValidation="False" OnClick="btnClear_Click" Text="Reset" UseSubmitBehavior="False" />
</div>
<div class="col form-group">
<asp:Button ID="btnRegister" CssClass="btn btn-success btn-block" runat="server" OnClick="btnRegister_Click" Text="Register" />
</div>
</div>
</article>
<div class="border-top card-body text-center">Have an account? Log In</div>
</div>
</div>
</div>
</div>
And this is my code behind:
protected void btnClear_Click(object sender, EventArgs e) {
txtFirstname.Text = "";
txtLastname.Text = "";
txtUsername.Text = "";
txtPassword.Text = "";
txtEmail.Text = "";
txtPhoneNumber.Text = "";
txtBirthdate.Text = "";
ddlGender.SelectedValue = "0";
Response.Write("<script>alert('Successfully Cleared!')</script>");
}
protected void btnRegister_Click(object sender, EventArgs e) {
SqlConnection conn = new SqlConnection(#"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|eMerch.mdf;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand("uspAddUser", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#uName", SqlDbType.NVarChar).Value = txtUsername.Text.Trim();
cmd.Parameters.AddWithValue("#uPassword", SqlDbType.NVarChar).Value = txtPassword.Text.Trim();
cmd.Parameters.AddWithValue("#responseMessage", SqlDbType.NVarChar);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('User Registration Success!')</script>");
conn.Close();
}
and this is my code for the modal in master page:
<div class="modal fade" runat="server" id="LoginModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-center modal-login">
<asp:UpdatePanel ID="upLogin" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<div class="modal-content">
<div class="modal-header">
<div class="avatar">
<img src="../Images/web/Avatar_Login.png" alt="Avatar">
</div>
<h4 class="modal-title">Member Login</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="alert alert-danger collapse text-center" id="errorCredentials">
Invalid Credentials
</div>
<div class="form-group">
<label class="col-form-label">Username:</label>
<asp:TextBox ID="txtUsername" runat="server" CssClass="form-control" required="required"></asp:TextBox>
</div>
<div class="form-group">
<label class="col-form-label">Password:</label>
<asp:TextBox ID="txtPassword" runat="server" CssClass="form-control" TextMode="Password" required="required"></asp:TextBox>
</div>
<div class="form-group">
<asp:Button ID="btnLogin" runat="server" CausesValidation="False" Text="Login" CssClass="btn btn-primary btn-lg btn-block login-btn" OnClick="btnLogin_Click"/>
</div>
</div>
<div class="modal-footer">
Forgot Password?
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
Okay i think its because you are using required="required" attribute in your code to make certain fields mandatory. When you click the register button it is causing this check validation on all fields so the ones in your modal div as well as the ones in card div. This is why its not getting to your register_onclick event. (the fields username and password or not validated as they are not entered)
You should be able to prove this by removing the required="required" from the password and username textboxes in the modal.
To add validation you could use the asp:RequiredFieldValidator instead of the required attribute for the textboxes etc you want to to make mandatory. see below
https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.requiredfieldvalidator?view=netframework-4.8
You can also add validation groups using so each button only validates certain controls. see below
https://learn.microsoft.com/en-us/previous-versions/aspnet/ms227424(v=vs.100)
Hope this helps. Please let me know if its worked.
It looks okay from the code but its difficult to tell whats happening without the rest of you code. what does your code for the button click events look like. e.g. below.
protected void btnRegister_Click(object sender, EventArgs e)
{
}
protected void btnClear_Click(object sender, EventArgs e)
{
}
Edit: i have just tried your code in a blank webforms project and it worked for me including the validation checks. so the error must be some where else on your page / in your project. The picture below shows it running and i set a break point on the btnRegister_Click event which its hitting when i press the button after filling in all the required fields.
My Example of your code running
You're doing nothing wrong with UseSubmitBehavior = false
Microsoft says:
Use the UseSubmitBehavior property to specify whether a Button control uses the client browser's submit mechanism or the ASP.NET postback mechanism. By default the value of this property is true, causing the Button control to use the browser's submit mechanism. If you specify false, the ASP.NET page framework adds client-side script to the page to post the form to the server.
https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.button.usesubmitbehavior?view=netframework-4.8
The browser uses form tag and grouping, like in MVC-5 flavour by default =true, because most programmers use MVC with ASP.NET.
You are using ASP.NET button events, not a form event. Consequently, UseSubmitBehavior=false is the correct setting.

Passing an ID of a row in Repeater to submit button in ASP NET

Since I'm using many viewstates, I'm trying to stop relying on them because pages take forever to load. I have this repeater with a table and when I click a button it enables a form that has another repeater. I need to pass the ID of the row of the 1st repeater so i can update the data related to that item on submit button.
Note. The ID i need is on the 1st column of repeater
<td>
<asp:Label ID="lblIdRegisto" runat="server" Text='<%# Eval("ID_Registo") %>' Style="display: none;" />
<asp:Label ID="lblReferenciaCliente" runat="server" Text='<%# Eval("Ref_Cliente") %>' />
</td>
here is my code
this is my submit button
protected void btnValidarFormulario_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string cnnStr = ConfigurationManager.ConnectionStrings["ValidacaoFormas_ConnectionString"].ConnectionString;
ADefinicao def = new ADefinicao();
def.ReferenciaInterna = txtRefInterna.Text;
def.Indice = txtIndice.Text;
def.Observacoes = txtObservacoes.Text;
def.isValid = "Sim";
def.DataValidacao = DateTime.Now.ToString("dd-MM-yyyy").ToString();
string nome = Session["Nome"].ToString();
int id = Convert.ToInt32(ViewState["id"]);
id = ADefinicao.UpdateADefinicao(nome, id, def);
ScriptManager.RegisterStartupScript(this, this.GetType(), "key_name", "ShowToast('success','Documento validado com sucesso.'); setTimeout(function(){window.location.href ='/Conta/Início.aspx'}, 3000);", true);
}
}
and this is the main repeater
<asp:Repeater ID="rptValidacao" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="rptValidacao_ItemCommand">
<HeaderTemplate>
<table id="tblValidarRegistos" class="table table-bordered table-striped table-hover dataTable text-center">
<thead class="thead-dark">
<tr>
<th class="text-center">Ref. Cliente</th>
<th class="text-center">Ref. Interna</th>
<th class="text-center">Índice</th>
<th class="text-center">Qtd. Formas</th>
<th class="text-center"></th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr style="font-size:15px;">
<td>
<asp:Label ID="lblIdRegisto" runat="server" Text='<%# Eval("ID_Registo") %>' Style="display: none;" />
<asp:Label ID="lblReferenciaCliente" runat="server" Text='<%# Eval("Ref_Cliente") %>' />
</td>
<td>
<asp:Label ID="lblReferenciaInterna" runat="server" Text='<%# Eval("Ref_Interna") %>' />
</td>
<td>
<asp:Label ID="lblIndicie" runat="server" Text='<%# Eval("Indice") %>' />
</td>
<td>
<asp:Label ID="lblQTDFormas" runat="server" Text='<%# Eval("QTD_Formas") %>' />
</td>
<td>
<asp:ImageButton ID="ibtnValidar" runat="server" ImageUrl="/Images/Icones/success.png" CommandName="Validar" CommandArgument='<%# Eval("ID_Registo") %>' Width="25" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
I was wondering if is there a way to pass an arguent from that repeater to this button
<asp:Button ID="btnValidarFormulario" CssClass="submit-button font-weight-bold" runat="server" Text="Validar Documentação" ValidationGroup="vgValidarDocumentacao" OnClick="btnValidarFormulario_Click" />
EDIT.
This the the form that appears when img button clicked on repeater with some data and needs to be updated, it's a bit long so i only posted cause i was asked. The submit button is at the end. I only need the ID where all the data on the form comes from and pass it to the submit button
<div id="divValidar" class="card card-danger shadow mx-auto custom-card-layout" visible="false" runat="server" style="min-width: 600px; max-width: 950px;">
<div class="card-header text-center custom-card-header">
<h3 class="card-title font-weight-bold">A - Definição</h3>
</div>
<!-- /.card-header -->
<!-- form start -->
<div class="card-body">
<div class="container">
<asp:ValidationSummary runat="server"
ID="ValidationSummary2"
DisplayMode="BulletList"
HeaderText="<b>Preencha todos os campos devidamente para proseguir.</b>"
ValidationGroup="vgADefinicao"
CssClass="alert validation-summary"
ShowSummary="true" />
<fieldset>
<legend>Informação Referêncial</legend>
<div class="row justify-content-center">
<div class="col-sm-4">
<div class="form-group col-10 mx-auto text-center">
<asp:Label ID="lblRefCliente" Text="1. Referência Cliente" AssociatedControlID="txtRefCliente" runat="server"></asp:Label>
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<asp:TextBox ID="txtRefCliente" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
</div>
</div>
<div class="col-sm-4">
<div class="form-group col-10 mx-auto">
<asp:Label ID="lblRefInterna" Text="2. Referência Interna" AssociatedControlID="txtRefInterna" runat="server"></asp:Label>
<asp:TextBox ID="txtRefInterna" CssClass="form-control form-control-sm border border-dark" runat="server" placeholder="Referência Interna"></asp:TextBox>
</div>
</div>
<div class="col-sm-4">
<div class="form-group col-10 mx-auto">
<asp:Label ID="lblIndice" Text="3. Índice" AssociatedControlID="txtIndice" runat="server"></asp:Label>
<asp:TextBox ID="txtIndice" CssClass="form-control form-control-sm border border-dark" runat="server" placeholder="Indíce"></asp:TextBox>
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>Casquilhos e Formas - Quantidade</legend>
<div class="row justify-content-center pb-4">
<div class="col-md-6">
</div>
<div class="col-md-6 text-center">
<strong>5. Quantidade de Casquilhos</strong>
</div>
</div>
<div class="row justify-content-center row-eq-height">
<div class="col-md-6">
<div class="form-group col-7 mx-auto text-center">
<asp:Label ID="lblQtdFormas" Text="4. Quantidade de Formas" AssociatedControlID="txtQtdFormas" runat="server"></asp:Label>
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<asp:TextBox ID="txtQtdFormas" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
</div>
</div>
<div class="col-md-6">
<div class="form-group col-7 mx-auto text-center">
<asp:Label ID="lblCasquilhosFixos" Text="5.1 Fixos" AssociatedControlID="txtCasquilhosFixos" runat="server"></asp:Label>
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<asp:TextBox ID="txtCasquilhosFixos" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
</div>
<div class="form-group col-7 mx-auto text-center">
<asp:Label ID="lblCasquilhosLivres" Text="5.2 Livres" AssociatedControlID="txtCasquilhosLivres" runat="server"></asp:Label>
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<asp:TextBox ID="txtCasquilhosLivres" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>Casquilhos e Formas - Diâmetros</legend>
<div class="row justify-content-center pb-4">
<div class="col-md-6 text-center">
<strong>6. Diâmetro dos casquilhos</strong>
</div>
<div class="col-md-6 text-center">
<strong>7. Diâmetro das formas</strong>
</div>
</div>
<div class="row justify-content-center">
<div class="col-md-6">
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblDiametroCasqLadoFixo" Text="6.1 Lado Fixo" AssociatedControlID="txtDiametroCasqLadoFixo" runat="server"></asp:Label>
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<div class="input-group input-group-sm">
<asp:TextBox ID="txtDiametroCasqLadoFixo" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
<div class="input-group-append border border-dark">
<span class="input-group-text"><strong>mm</strong></span>
</div>
</div>
</div>
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblDiametroCasqLadoMovel" Text="7.2 Lado Móvel" AssociatedControlID="lblDiametroCasqLadoMovel" runat="server"></asp:Label>
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<div class="input-group input-group-sm">
<asp:TextBox ID="txtDiametroCasqLadoMovel" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
<div class="input-group-append border border-dark">
<span class="input-group-text"><strong>mm</strong></span>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblDiametroFormasFixo" Text="7.1 Lado fixo" AssociatedControlID="txtDiametroFormasFixo" runat="server"></asp:Label>
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<div class="input-group input-group-sm">
<asp:TextBox ID="txtDiametroFormasFixo" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
<div class="input-group-append border border-dark">
<span class="input-group-text"><strong>mm</strong></span>
</div>
</div>
</div>
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblDiametroFormasMovel" Text="7.2 Lado Móvel" AssociatedControlID="txtDiametroFormasMovel" runat="server"></asp:Label>
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<div class="input-group input-group-sm">
<asp:TextBox ID="txtDiametroFormasMovel" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
<div class="input-group-append border border-dark">
<span class="input-group-text"><strong>mm</strong></span>
</div>
</div>
</div>
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblDiametroFormasCorpo" Text="7.2 Corpo" AssociatedControlID="txtDiametroFormasCorpo" runat="server"></asp:Label>
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<div class="input-group input-group-sm">
<asp:TextBox ID="txtDiametroFormasCorpo" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
<div class="input-group-append border border-dark">
<span class="input-group-text"><strong>mm</strong></span>
</div>
</div>
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>Cru
<small>(A preencher pela Extrusão)</small>
</legend>
<div class="row justify-content-center pb-4">
<div class="col-md-6 text-center">
<strong>8. Informação do Cru</strong>
</div>
<div class="col-md-6 text-center">
<strong>8.3 Parâmetros do cru:</strong>
</div>
</div>
<div class="row justify-content-center">
<div class="col-md-6">
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblCruBase" Text="8.1 Base" AssociatedControlID="txtCruBase" runat="server"></asp:Label>
<asp:TextBox ID="txtCruBase" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
</div>
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblCruLinha" Text="8.2 Linha" AssociatedControlID="txtCruLinha" runat="server"></asp:Label>
<asp:TextBox ID="txtCruLinha" CssClass="form-control form-control-smborder border-dark" runat="server" ReadOnly="true"></asp:TextBox>
</div>
<div class="form-group col-10 mx-auto text-center">
<asp:Label ID="lblMarcacaoContinua" Text="8.4 Marcação contínua" AssociatedControlID="txtMarcacaoContinua" runat="server" />
<small class="text-muted">(texto + cor)</small>
<asp:TextBox ID="txtMarcacaoContinua" TextMode="MultiLine" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true" />
</div>
</div>
<div class="col-md-6">
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblCruDiametro" Text="Diâmetro" AssociatedControlID="txtCruDiametro" runat="server"></asp:Label>
<div class="input-group input-group-sm">
<asp:TextBox ID="txtCruDiametro" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
<div class="input-group-append border border-dark">
<span class="input-group-text"><strong>mm</strong></span>
</div>
</div>
</div>
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblCruEspessura" Text="Espessura" AssociatedControlID="txtCruEspessura" runat="server"></asp:Label>
<div class="input-group input-group-sm">
<asp:TextBox ID="txtCruEspessura" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
<div class="input-group-append border border-dark">
<span class="input-group-text"><strong>mm</strong></span>
</div>
</div>
</div>
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblComprimento" Text="Comprimento" AssociatedControlID="txtComprimento" runat="server"></asp:Label>
<div class="input-group input-group-sm">
<asp:TextBox ID="txtComprimento" CssClass="form-control form-control-sm border border-dark" runat="server" ReadOnly="true"></asp:TextBox>
<div class="input-group-append border border-dark">
<span class="input-group-text"><strong>mm</strong></span>
</div>
</div>
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>9. Datas Previstas</legend>
<div class="row justify-content-center">
<div class="col-md-6">
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblDataFormasPreSerie" runat="server" AssociatedControlID="txtReadOnlyDataFormasPreSerie" Text="9.1 Formas Pré-Série" />
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<div class="input-group input-group-sm">
<div class="input-group-prepend border border-dark">
<span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
</div>
<asp:TextBox ID="txtReadOnlyDataFormasPreSerie" runat="server" class="form-control form-control-sm border border-dark" ReadOnly="true" />
</div>
</div>
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblDataFormasSerie" runat="server" AssociatedControlID="txtReadOnlyDataFormasSerie" Text="9.3 Formas Série" />
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<div class="input-group input-group-sm">
<div class="input-group-prepend border border-dark">
<span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
</div>
<asp:TextBox ID="txtReadOnlyDataFormasSerie" runat="server" class="form-control form-control-sm border border-dark" ReadOnly="true" />
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblDataAmostrasIniciais" runat="server" AssociatedControlID="txtReadOnlyDataAmostrasIniciais" Text="9.2 Amostras iniciais" />
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<div class="input-group input-group-sm">
<div class="input-group-prepend border border-dark">
<span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
</div>
<asp:TextBox ID="txtReadOnlyDataAmostrasIniciais" runat="server" class="form-control form-control-sm border border-dark" ReadOnly="true" />
</div>
</div>
<div class="form-group col-6 mx-auto text-center">
<asp:Label ID="lblDataArranqueProducao" runat="server" AssociatedControlID="txtReadOnlyDataArranqueProducao" Text="9.4 Arranque Produção" />
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<div class="input-group input-group-sm">
<div class="input-group-prepend border border-dark">
<span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
</div>
<asp:TextBox ID="txtReadOnlyDataArranqueProducao" runat="server" class="form-control form-control-sm border border-dark" ReadOnly="true" />
</div>
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>Documentos</legend>
<div class="row justify-content-center">
<div class="col-md-12">
<asp:Repeater ID="rptAnexos" runat="Server" OnItemCommand="rptAnexos_ItemCommand">
<HeaderTemplate>
<table id="tblAnexos" class="table-sm table table-striped table-bordered text-center rounded" style="border-radius: 10px;">
<caption>Lista de Anexos</caption>
<thead class="thead-dark">
<tr>
<th>ID</th>
<th>Tipo Desenho</th>
<th>Nome Ficheiro</th>
<th>Inserido Por</th>
<th></th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr style="font-size:small">
<td>
<asp:Label ID="lblIdRegisto" runat="server" Text=' <%# Eval("ID_Registo") %>' />
</td>
<td>
<asp:Label ID="lblTipoDesenho" runat="server" Text=' <%# Eval("Tipo") %>' />
</td>
<td>
<asp:Label ID="lblNomeAnexo" runat="server" Text='<%# Eval("NomeAnexo") %>' />
</td>
<td>
<asp:Label ID="lblPiloto" runat="server" Text='<%# Eval("Piloto") %>' />
</td>
<td class="text-center">
<asp:ImageButton runat="server" ImageUrl="/Images/Icones/download.png" Width="20" CommandName="Download" CommandArgument='<%# Eval("ID") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</div>
</fieldset>
<fieldset>
<legend>Observações</legend>
<div class="row justify-content-center row-eq-height">
<div class="col-md-12">
<div class="form-group col-7 mx-auto text-center">
<asp:Label ID="lblObservacoes" Text="Observações" AssociatedControlID="txtObservacoes" runat="server"></asp:Label>
<i class="fas fa-asterisk text-danger mb-2" style="font-size: 8px;"></i>
<asp:TextBox ID="txtObservacoes" CssClass="form-control form-control-sm border border-dark" runat="server" TextMode="MultiLine" Rows="3"></asp:TextBox>
<div class="valid-feedback">Success! You've done it.</div>
<i class="glyphicon glyphicon-ok form-control-feedback"></i>
<div class="valid-feedback feedback-icon">
<i class="fa fa-check"></i>
</div>
<div class="invalid-feedback feedback-icon">
<i class="fa fa-times"></i>
</div>
<asp:CustomValidator ID="cvObservacoes" runat="server" EnableClientScript="True" ValidationGroup="vgValidarDocumentacao" Display="Dynamic" ValidateEmptyText="True" ClientValidationFunction="CustomValidator" CssClass="server-validator" ControlToValidate="txtObservacoes"></asp:CustomValidator>
<asp:RequiredFieldValidator ID="rfvObservacoes" runat="server" CssClass="server-validator" ValidationGroup="vgValidarDocumentacao" SetFocusOnError="True" ControlToValidate="txtObservacoes" Text="Campo necessário." ErrorMessage="<b>Observações:</b> Campo necessário." Display="Dynamic"></asp:RequiredFieldValidator>
</div>
</div>
</div>
</fieldset>
</div>
</div>
<!-- /.card-body -->
<div class="card-footer custom-card-footer">
<asp:Button ID="btnValidarFormulario" CssClass="submit-button font-weight-bold" runat="server" Text="Validar Documentação" ValidationGroup="vgValidarDocumentacao" OnClick="btnValidarFormulario_Click" />
</div>
<!-- /.card-footer -->
</div>
You can place a Label in an ItemTemplate and set the Visibility to false.
<asp:Repeater ID="rptValidacao" runat="server">
<ItemTemplate>
<asp:Label ID="LabelID" runat="server" Text='<%# Eval("id") %>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:Repeater>
But the Label still exists with the correct value if you use FindCOntrol in the Button Click event
protected void btnValidarFormulario_Click(object sender, EventArgs e)
{
Label lbl = rptValidacao.Items[i].FindControl("LabelID") as Label;
}
You should also look into DataKeys. But a Repeater cannot use them.
A solution is to create a HiddenField and on data bind of the repeater yourHiddenField.Value will be populated to something like:
3,4,7,12
and then on button click split the values in the hidden field. You can do this even on the client-side if the hidden field is populated via Javascript before submission is executed.

File upload control inside dialog box has no file in asp.net c#

I'm trying to upload a file using file upload control in asp.net
control is inside dialog box. On button click event, control is empty.
below is my code. edited here please check it.
<div class="modal fade" id="myModal_family" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body row">
<div class="col-md-12">
<div id="add1">
<div class="fileupload fileupload-new" data-provides="fileupload">
<p>
Title
<asp:TextBox ID="txtTitle" runat="server" CssClass="form-control"></asp:TextBox></p>
<span class="btn btn-white btn-file"><span class="fileupload-new"><i class="fa fa-paper-clip">
</i>Select file</span>
<asp:FileUpload ID="upldfile" runat="server" onchange="UploadFile(this)" ClientIDMode="Static" />
</span>
<p> <br />
<asp:Button ID="btnSave" runat="server" UseSubmitBehavior="false" data-dismiss="modal" OnClick="Upload" Style="display: none" class="btn btn-danger" /></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
javascript here:
<script type="text/javascript">
function UploadFile(fileUpload) {
alert(fileUpload);
if (fileUpload.value != '') {
document.getElementById("<%=btnSave.ClientID%>").click();
}
}
code behind:
public void Upload(object sender, EventArgs e)
{
Response.Write("sfzsfg");
if (upldfile.HasFile) // upldfile is null here
{
}
}
your code is proper I have just put trigger and it working
<asp:UpdatePanel ID="updatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<div id="add1">
<div class="fileupload fileupload-new" data-provides="fileupload">
<p>
Title
<asp:TextBox ID="txtTitle" runat="server" CssClass="form-control"></asp:TextBox>
</p>
<span class="btn btn-white btn-file"><span class="fileupload-new"><i class="fa fa-paper-clip"></i>Select file</span>
<asp:FileUpload ID="upldfile" runat="server" onchange="UploadFile(this)" />
</span>
<p>
<br />
<asp:Button ID="btnSave" runat="server" UseSubmitBehavior="false" data-dismiss="modal" OnClick="Upload" Style="display: none" class="btn btn-danger" />
</p>
</div>
</div>
</ContentTemplate>
<%-- <Triggers>
<asp:PostBackTrigger ControlID="btnSave" />
</Triggers>--%>
</asp:UpdatePanel>
rest thing is same as you have posted
Please try.

ASP.NET Webform fill bootstrap modal from code behind

I have a gridview in my page, and when Edit button is clicked, it will display a bootstrap modal, named modalEditPurchase, and display data. I have tried to populate the fields in the modal from code-behind but it didn't work, the fields are not populated.
Can anyone advise what I did wrong?
Thank you in advance.
HTML
<div class="form-group">
<div class="col-md-2">
<a id="hypAddPurchase" data-toggle="modal" data-target="#modalAddPurchase" class="btn btn-primary" <%--style="float: left;"--%>>
<span class="glyphicon glyphicon-plus"></span> Add Purchase
</a>
</div>
</div>
<div class="form-group">
<div class="col-md-11">
<div class="container">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-hover"
DataKeyNames="ID">
<Columns>
<asp:BoundField DataField="ID" HeaderText="Id" />
<asp:BoundField DataField="PRODUCT_CODE" HeaderText="Fund Code" />
<asp:BoundField DataField="PRODUCT_NAME" HeaderText="Fund Name" />
<asp:BoundField DataField="" HeaderText="Fund Currency" />
<asp:BoundField DataField="INVEST_AMT" HeaderText="Amount Invest" />
<asp:BoundField DataField="" HeaderText="Payment Currency" />
<asp:BoundField DataField="ENTRY_FEE_RATE" HeaderText="Entry Fee %" />
<asp:BoundField DataField="ENTRY_FEE_AMT" HeaderText="Entry Fee Amount" />
<asp:BoundField DataField="GST_RATE" HeaderText="GST %" />
<asp:BoundField DataField="GST_AMT" HeaderText="GST Amount" />
<asp:BoundField DataField="TRANS_AMT" HeaderText="Transaction Amount" />
<asp:BoundField DataField="FX_RATE" HeaderText="FX Rate" Visible="False" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" CommandName="Edit" data-toggle="modal" data-target="#modalEditPurchase" CssClass="btn btn-primary btn-sm" OnClick="OpenEdit_OnClick"><span class="glyphicon glyphicon-pencil"></span> Edit</asp:LinkButton>
<asp:LinkButton runat="server" CommandName="Delete" CssClass="btn btn-primary btn-sm"><span class="glyphicon glyphicon-minus"></span> Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
</div>
<div class="modal fade" id="modalEditPurchase" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="modalEditPurchaseLabel">Edit Purchase</h4>
</div>
<div class="modal-body">
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Fund:</label>
</div>
<div class="col-md-5">
<asp:DropDownList class="form-control chosen-select_inModal" ID="ddlFundEdit" Width="400" runat="server"></asp:DropDownList>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Fund Currency:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" ID="txtFundCurrencyEdit" CssClass="form-control"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Amount Invest:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtAmountInvestEdit" CssClass="form-control" placeholder="00.00"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Payment Currency:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtPaymentCurrencyEdit" CssClass="form-control" placeholder="Payment Currency"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">FX Rate:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtFxRateEdit" CssClass="form-control" placeholder ="FX Rate"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Entry Fee %:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtEntryFeeRateEdit" CssClass="form-control" placeholder="Entry Fee Rate %"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Entry Fee:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtEntryFeeAmtEdit" CssClass="form-control" placeholder="00.00"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">GST %:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtGstRateEdit" CssClass="form-control" placeholder="GST Rate %"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">GST Amount:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtGstAmtEdit" CssClass="form-control" placeholder="00.00"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Trans Amount:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtTransAmtEdit" CssClass="form-control" placeholder="00.00"></asp:TextBox>
</div>
</ul>
</div>
<div class="modal-footer">
<asp:Button runat="server" CssClass="btn btn-primary" ID="btnEdit" Text="Update" UseSubmitBehavior="false" OnClick="btnEdit_Click"/>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="modalAddPurchase" tabindex="-1" role="dialog">
<div class="modal-dialog" style="width: 768px;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="modalAddPurchaseLabel">Add Purchase</h4>
</div>
<div class="modal-body">
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Fund:</label>
</div>
<div class="col-md-5">
<asp:DropDownList class="form-control chosen-select_inModal" ID="ddlFundAdd" Width="400" runat="server"></asp:DropDownList>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Fund Currency:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" ID="txtFundCurrencyAdd" CssClass="form-control"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Amount Invest:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtAmountInvestAdd" CssClass="form-control" placeholder="Amount Invest"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Payment Currency:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtPaymentCurrencyAdd" CssClass="form-control" placeholder="Payment Currency"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">FX Rate:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtFxRateAdd" CssClass="form-control" placeholder ="FX Rate"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Entry Fee %:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtEntryFeeRateAdd" CssClass="form-control"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Entry Fee:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtEntryFeeAmtAdd" CssClass="form-control"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">GST %:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtGstRateAdd" CssClass="form-control"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">GST Amount:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtGstAmtAdd" CssClass="form-control"></asp:TextBox>
</div>
</ul>
<ul class="row">
<div class="col-md-4" align="right">
<label class="control-label">Trans Amount:</label>
</div>
<div class="col-md-5">
<asp:TextBox runat="server" id="txtTransAmtAdd" CssClass="form-control" placeholder="Transaction Amount"></asp:TextBox>
</div>
</ul>
</div>
<div class="modal-footer">
<asp:Button runat="server" CssClass="btn btn-primary" ID="btnAdd" Text="Add" UseSubmitBehavior="false" OnClick="btnAdd_Click" data-dismiss="modal"/>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
C#
protected void OpenEdit_OnClick(object sender, EventArgs e)
{
if (gvDetails.Rows.Count > 0)
{
GridViewRow row = gvDetails.SelectedRow;
ddlFundEdit.SelectedValue = row.Cells[1].Text;
txtFundCurrencyEdit.Text = row.Cells[3].Text;
txtAmountInvestEdit.Text = row.Cells[4].Text;
txtPaymentCurrencyEdit.Text = row.Cells[5].Text;
txtEntryFeeRateEdit.Text = row.Cells[6].Text;
txtEntryFeeAmtEdit.Text = row.Cells[7].Text;
txtGstRateEdit.Text = row.Cells[8].Text;
txtGstAmtEdit.Text = row.Cells[9].Text;
txtTransAmtEdit.Text = row.Cells[10].Text;
txtFxRateEdit.Text = row.Cells[11].Text;
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
int rowIndex = 0;
DataTable dtCurrentTable = new DataTable();
DataRow drCurrentRow = null;
if (ViewState["CurrentTable"] != null)
{
dtCurrentTable = (DataTable) ViewState["CurrentTable"];
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
// Extract current values in table
string id = gvDetails.Rows[rowIndex].Cells[0].Text;
string fund = gvDetails.Rows[rowIndex].Cells[1].Text;
string fundName = gvDetails.Rows[rowIndex].Cells[2].Text;
string fundCurrency = gvDetails.Rows[rowIndex].Cells[3].Text;
string amountInvest = gvDetails.Rows[rowIndex].Cells[4].Text;
string paymentCurrency = gvDetails.Rows[rowIndex].Cells[5].Text;
string entryFeeRate = gvDetails.Rows[rowIndex].Cells[6].Text;
string entryFeeAmount = gvDetails.Rows[rowIndex].Cells[7].Text;
string gstRate = gvDetails.Rows[rowIndex].Cells[8].Text;
string gstAmount = gvDetails.Rows[rowIndex].Cells[9].Text;
string transactionAmount = gvDetails.Rows[rowIndex].Cells[10].Text;
string fxRate = gvDetails.Rows[rowIndex].Cells[11].Text;
dtCurrentTable.Rows[i - 1]["ID"] = id;
dtCurrentTable.Rows[i - 1]["PRODUCT_CODE"] = fund;
dtCurrentTable.Rows[i - 1]["PRODUCT_NAME"] = fundName;
dtCurrentTable.Rows[i - 1]["FUND_CURRENCY"] = fundCurrency;
dtCurrentTable.Rows[i - 1]["INVEST_AMT"] = amountInvest;
dtCurrentTable.Rows[i - 1]["PAYMENT_CURRENCY"] = paymentCurrency;
dtCurrentTable.Rows[i - 1]["ENTRY_FEE_RATE"] = entryFeeRate;
dtCurrentTable.Rows[i - 1]["ENTRY_FEE_AMT"] = entryFeeAmount;
dtCurrentTable.Rows[i - 1]["GST_RATE"] = gstRate;
dtCurrentTable.Rows[i - 1]["GST_AMT"] = gstAmount;
dtCurrentTable.Rows[i - 1]["TRANS_AMT"] = transactionAmount;
dtCurrentTable.Rows[i - 1]["FX_RATE"] = fxRate;
rowIndex++;
}
}
}
else
{
dtCurrentTable.Columns.Add("ID", typeof(string));
dtCurrentTable.Columns.Add("PRODUCT_CODE", typeof(string));
dtCurrentTable.Columns.Add("PRODUCT_NAME", typeof(string));
dtCurrentTable.Columns.Add("FUND_CURRENCY", typeof(string));
dtCurrentTable.Columns.Add("INVEST_AMT", typeof(string));
dtCurrentTable.Columns.Add("PAYMENT_CURRENCY", typeof(string));
dtCurrentTable.Columns.Add("ENTRY_FEE_RATE", typeof(string));
dtCurrentTable.Columns.Add("ENTRY_FEE_AMT", typeof(string));
dtCurrentTable.Columns.Add("GST_RATE", typeof(string));
dtCurrentTable.Columns.Add("GST_AMT", typeof(string));
dtCurrentTable.Columns.Add("TRANS_AMT", typeof(string));
dtCurrentTable.Columns.Add("FX_RATE", typeof(string));
}
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["ID"] = rowIndex + 1;
drCurrentRow["PRODUCT_CODE"] = ddlFundAdd.SelectedValue;
drCurrentRow["PRODUCT_NAME"] = ddlFundAdd.SelectedItem.Text;
drCurrentRow["FUND_CURRENCY"] = txtFundCurrencyAdd.Text;
drCurrentRow["INVEST_AMT"] = txtAmountInvestAdd.Text;
drCurrentRow["PAYMENT_CURRENCY"] = txtPaymentCurrencyAdd.Text;
drCurrentRow["ENTRY_FEE_RATE"] = txtEntryFeeRateAdd.Text;
drCurrentRow["ENTRY_FEE_AMT"] = txtEntryFeeAmtAdd.Text;
drCurrentRow["GST_RATE"] = txtGstRateAdd.Text;
drCurrentRow["GST_AMT"] = txtGstAmtAdd.Text;
drCurrentRow["TRANS_AMT"] = txtTransAmtAdd.Text;
drCurrentRow["FX_RATE"] = txtFxRateAdd.Text;
dtCurrentTable.Rows.Add(drCurrentRow);
ViewState["CurrentTable"] = dtCurrentTable;
BindGrid();
}
protected void BindGrid()
{
if (ViewState["CurrentTable"] != null)
{
gvDetails.DataSource = ViewState["CurrentTable"] as DataTable;
}
else
{
gvDetails.DataSource = null;
}
gvDetails.DataBind();
}
Everything should be inside the asp:UpdatePanel tag, even the modal <div class="modal fade" ...>. That should work.
That's the way UpdatePanels work: when a server call is triggered, only their ContentTemplate area is updated (even when you try to update other parts of the page).
EDIT
I think there's a problem with the UpdatePanel's trigger: it should be directed to the grid's click event, but currently it doesn't seem to be the case.
The Edit button already has a command configured: CommandName="Edit", so you need to capture the OnRowCommand event of the grid, like this:
<asp:GridView ID="gvDetails" ... OnRowCommand="grid_RowCommand">
also change the UpdatePanel's trigger, like this:
<asp:AsyncPostBackTrigger ControlID="gvDetails" EventName="OnRowCommand" />
and in code behind:
protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
// your current OpenEdit_OnClick code
}
}
GridViewRow row = (sender as LinkButton).NamingContainer as GridViewRow;
Now get your data from row.
Just to update and let you know that I have managed to solve this issue earlier.
1) I changed the LinkButton in the gridview to Button
2) Added this in the OnEdit_Click:
Button btn = sender as Button;
GridViewRow row = btn.NamingContainer as GridViewRow;
string id = gvDetails.DataKeys[row.RowIndex].Values[0].ToString();
3) Put modalEditPurchase inside an UpdatePanel
4) Populate the modalEditPurchase using the id.
Thank you everyone for your help.

Asp:Button not firing in bootstrap Tab Panes

I have set a bootstrap tab pane, within this tab pane there is a form, on asp:Button press the code will not execute.
I know the code works as when not in the tab pane it works every time.
But its for a user control page and would be better to provide function within the tab panes.
This is for all buttons within the tab pane.
if one gets solved then the method to repair others is made!
Here is the HTML markup:
<div class="tab-content col-lg-10">
<div class="tab-pane active" id="pane1">
<%--Content goes in here, so tables, and whatever else--%>
<h3>My Bookings</h3>
<div class="container">
<asp:GridView runat="server" ID="dgBookingView" AutoGenerateColumns="False" DataSourceID="myBookings" CssClass="table table-striped table-bordered" UseAccessibleHeader="True">
<Columns>
<asp:BoundField DataField="BookingID" HeaderText="Booking #" InsertVisible="False" SortExpression="BookingID" />
<asp:BoundField DataField="FilmName" HeaderText="Movie" SortExpression="FilmName" />
<asp:BoundField DataField="Requirements" HeaderText="Requirements" SortExpression="Requirements" />
<asp:BoundField DataField="Showtime" HeaderText="Time" SortExpression="Showtime" DataFormatString="{0:t}" />
<asp:BoundField DataField="ShowDate" HeaderText="Date" SortExpression="ShowDate" DataFormatString="{0:d}" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="myBookings" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT Booking.BookingID, Booking.CustomerFK, Booking.AuditorumFK, Booking.Requirements, Film.FilmName, Showtime.Showtime, Showtime.ShowDate, Showtime.AuditoriumID, Customers.UserNameFK FROM (((((Booking INNER JOIN Seat ON Booking.BookingID = Seat.BookingFK) INNER JOIN Auditorium ON Seat.AuditoriumFK = Auditorium.AuditoriumID) INNER JOIN Showtime ON Auditorium.AuditoriumID = Showtime.AuditoriumID) INNER JOIN Film ON Showtime.FilmFK = Film.FilmID) INNER JOIN Customers ON Booking.CustomerFK = Customers.CustomerID)
WHERE([Customers.UserNameFK] = ? )">
<SelectParameters>
<asp:SessionParameter
Name="userNamePa"
SessionField="userName"
DefaultValue="userName" />
</SelectParameters>
</asp:SqlDataSource>
</div>
<div class="row">
<h3>Specify any Special Requirements</h3>
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">Booking #</label>
<div class="col-sm-6">
<asp:TextBox runat="server" CssClass="form-control" ID="txtBookingID"></asp:TextBox>
</div>
<div class="col-sm-4">
<h4>
<asp:RequiredFieldValidator ID="rqfUserNameValid" ControlToValidate="txtBookingID" runat="server"
ErrorMessage="Enter a Booking Number" CssClass="label label-danger">
</asp:RequiredFieldValidator>
</h4>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Extra Requirements</label>
<div class="col-sm-6">
<asp:TextBox ID="txtRequirements" class="form-control" Rows="5" runat="server"></asp:TextBox>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-6">
<asp:Button runat="server" CssClass="btn btn-default" Text="Make Change" ID="btnRequirements" OnClick="btnRequirements_OnClick" />
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="pane2" runat="server">
<%--Change User Password START--%>
<h3>Change Password</h3>
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">Current Password</label>
<div class="col-sm-6">
<asp:TextBox runat="server" CssClass="form-control" ID="txtCurrentPass" TextMode="Password"></asp:TextBox>
</div>
<div class="col-sm-4">
<h4>
<asp:RequiredFieldValidator runat="server" CssClass="label label-danger" ID="rqfCurrentPassword" ControlToValidate="txtCurrentPass"
ErrorMessage="Enter Current Password">
</asp:RequiredFieldValidator>
</h4>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">New Password</label>
<div class="col-sm-6">
<asp:TextBox runat="server" CssClass="form-control" TextMode="Password" ID="txtNewPassword"></asp:TextBox>
</div>
<div class="col-sm-4">
<h4>
<asp:RequiredFieldValidator runat="server" CssClass="label label-danger" ID="rqfNewPassword" ControlToValidate="txtNewPassword"
ErrorMessage="Required">
</asp:RequiredFieldValidator>
</h4>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Confirm Password</label>
<div class="col-sm-6">
<asp:TextBox runat="server" CssClass="form-control" TextMode="Password" ID="txtConfirmPassword"></asp:TextBox>
</div>
<div class="col-sm-4">
<h4>
<asp:RequiredFieldValidator runat="server" CssClass="label label-danger" ID="rqfConfirmPassword" ControlToValidate="txtConfirmPassword"
ErrorMessage="Required">
</asp:RequiredFieldValidator>
</h4>
<h4>
<asp:CompareValidator runat="server" ControlToValidate="txtConfirmPassword" ControlToCompare="txtNewPassword" ID="PassCompare" ErrorMessage="Confirm password must match password" CssClass="label label-danger"></asp:CompareValidator>
</h4>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-6">
<asp:Button runat="server" CssClass="btn btn-default" Text="Change Password" ID="btnPasswordChange" OnClick="btnChangePassword_OnClick"></asp:Button>
</div>
</div>
</div>
<div class="col-sm-4">
<h4>
<asp:Label runat="server" CssClass="label label-danger" ID="lblPassChange" Visible="False" Text=""></asp:Label>
</h4>
</div>
</div>
<%--Change User Password--%>
</div>
</div>
And the C# Code for button Event:
protected void btnChangePassword_OnClick(object sender, EventArgs eventArgs)
{
//Changes Password of current Logged in User
string oldPass = txtCurrentPass.Text;
string newPass = txtNewPassword.Text;
MembershipUser user = Membership.GetUser(User.Identity.Name);
if (txtCurrentPass.Text == txtNewPassword.Text)
{
lblPassChange.Visible = true;
lblPassChange.Text = "Old Password must not match New Password";
}
else
{
if (user != null && user.ChangePassword(oldPass, newPass))
{
lblPassChange.Visible = true;
lblPassChange.Text = "Password Changed Successfully";
lblPassChange.CssClass = "label label-success";
}
else
{
lblPassChange.Visible = true;
lblPassChange.Text = "Error, Please try again";
}
}
}
Where am i going wrong?
Any help would be appreciated

Categories