Postingan lainnya
Seputar asp.net c# modal bootstrape tetap muncul setelah di autopostback
Listboxnya udah saya kasih autopostback. Gimana caranya supaya modal tetap muncul ketika sudah memilih item di listbox?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using INVENTORI.Classes;
namespace INVENTORI
{
public partial class Antrian : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["id"] != null)
{
if (!IsPostBack)
{
Username.Text = Session["id"].ToString();
DropdownList();
TampilData();
}
}
else
{
Response.Redirect("login.aspx");
}
}
protected void BtnLogout_Click(object sender, EventArgs e)
{
Session.RemoveAll();
Session.Abandon();
Response.Redirect("login.aspx");
}
protected void BtnSave_Click(object sender, EventArgs e)
{
ClsAntrian.SimpanUser(TxtNamaPL.Text, TxtAlamat.Text);
TampilData();
Bersih();
}
public void Bersih()
{
TxtNamaPL.Text = string.Empty;
TxtAlamat.Text = string.Empty;
}
private void TampilData()
{
DataTable Dt = new DataTable();
Dt = ClsAntrian.Tampildata();
RptTampilUser.DataSource = Dt;
RptTampilUser.DataBind();
}
private void DropdownList()
{
DataTable Dt = new DataTable();
Dt = ClsAntrian.Dropdown();
ddlNIK.DataSource = Dt;
ddlNIK.DataTextField = "nik";
ddlNIK.DataValueField = "nik";
ddlNIK.DataBind();
ddlNIK.Items.Insert(0, new ListItem(null, "--PILIH NIK--"));
}
protected void ddlNIK_TextChanged(object sender, EventArgs e)
{
DataTable DtTextChange = new DataTable();
DtTextChange = ClsAntrian.TextChange(ddlNIK.Text);
TxtAlamat.Text = DtTextChange.Rows[0][1].ToString();
TxtNamaPL.Text = DtTextChange.Rows[0][5].ToString();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Antrian.aspx.cs" Inherits="INVENTORI.Antrian" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<link href="addictional/css/global.css" rel="stylesheet" />
<link href="bootstrape4/css/bootstrap.css" rel="stylesheet" />
<link href="addictional/css/jquery.dataTables.min.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-primary">
<!--brand-->
<a class="navbar-brand" href="#">Navbar</a>
<!--toggle-->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!--Menubar-->
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="HomePage.aspx">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="Antrian.aspx">Antrian <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="Poli.aspx">Poli <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
DATA PASIEN
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="PasienLuar.aspx">LUAR</a>
<a class="dropdown-item" href="#">DALAM</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
<div class="form-inline my-2 my-lg-0">
<h5 class="mt-2 "> User : <asp:Label ID="Username" runat="server"></asp:Label> </h5>
<asp:LinkButton ID="BtnLogout" CssClass="mr-3 ml-3 mt-1 text-dark" runat="server" OnClick="BtnLogout_Click">Logout</asp:LinkButton>
</div>
</div>
<!--Menubar-->
</nav>
</header>
<main role="main">
<div class="container mt-5 mb-5">
<asp:Repeater ID="RptTampilUser" runat="server">
<HeaderTemplate>
<h1><center>TABEL USER</center></h1>
<button class="btn btn-primary btn-sm float-right mb-2" type="button" data-target="#ModalTambah" data-toggle="modal">Tambah Data</button>
<table id="myTable" class="table table-hover table-striped table-bordered ">
<thead>
<tr class="text-center">
<th>NO.ID ANTRIAN</th>
<th>NO. ANTRIAN</th>
<th>DATA ANTRIAN</th>
<th>KETERANGAN</th>
<th>OPSI</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr class="text-center">
<td><%# Eval("idAntrian") %></td>
<td><%# Eval("noAntrian") %></td>
<td><%# Eval("dataAntrian") %></td>
<td><%# Eval("Keterangan") %></td>
<td>
<a id="Edit_datauser" data-toggle="modal" data-target="#ModalEdit" data-id="<%# Eval("idUser") %>" data-nama="<%# Eval("Username") %>" data-pass="<%# Eval("Password") %>" data-namal="<%# Eval("namaLengkap") %>" class="btn btn-warning btn-sm text-white">Edit</a>
<a id="Hapus_datauser" data-toggle="modal" data-target="#ModalHapus" data-id="<%# Eval("idUser") %>" data-nama="<%# Eval("Username") %>" class="btn btn-danger btn-sm text-white">Hapus</a>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
<button class="btn btn-primary btn-sm" type="button" data-target="#ModalTambah" data-toggle="modal">Tambah Data</button>
</div>
<!-- Modal Tambah Data-->
<div class="modal fade" id="ModalTambah" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Form Tambah Data User</h5>
<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-group">
<asp:Label ID="Label1" runat="server" Text="NIK"></asp:Label>
<asp:DropDownList ID="ddlNIK" OnTextChanged="ddlNIK_TextChanged" AutoPostBack="true" CssClass="form-control" runat="server"></asp:DropDownList>
</div>
<div class="form-group">
<asp:Label ID="Label2" runat="server" Text="NAMA PASIEN LUAR"></asp:Label>
<asp:TextBox ID="TxtNamaPL" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<asp:Label ID="Label4" runat="server" Text="ALAMAT"></asp:Label>
<asp:TextBox ID="TxtAlamat" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<asp:Label ID="Label3" runat="server" Text="KETERANGAN"></asp:Label>
<asp:TextBox ID="TxtNamalengkap" CssClass="form-control" runat="server"></asp:TextBox>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
<asp:Button ID="BtnSave" OnClick="BtnSave_Click" CssClass="btn btn-primary" runat="server" Text="Tambah" />
</div>
</div>
</div>
</div>
</main>
<footer></footer>
</form>
<script src="addictional/js/jquery-3.3.1.slim.min.js"></script>
<script src="addictional/js/popper.min.js"></script>
<script src="bootstrape4/js/bootstrap.min.js"></script>
<script src="addictional/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$('#myTable').DataTable();
});
$(document).on("click", "#Edit_datauser", function () {
var _id = $(this).data("id");
var _nama = $(this).data("nama");
var _pass = $(this).data("pass");
var _namal = $(this).data("namal");
$("#ModalEdit #TxtEditId").val(_id);
$("#ModalEdit #TxtEditUsername").val(_nama);
$("#ModalEdit #TxtEditPassword").val(_pass);
$("#ModalEdit #TxtEditNL").val(_namal);
$("#ModalEdit #TxtEditId").attr("ReadOnly", true);;
})
$(document).on("click", "#Hapus_datauser", function () {
var _id = $(this).data("id");
var _nama = $(this).data("nama");
$("#ModalHapus #TxtHapusId").val(_id);
$("#ModalHapus #TxtHapusUsername").val(_nama);
$("#ModalHapus #TxtHapusId").attr("ReadOnly", true);;
$("#ModalHapus #TxtHapusUsername").attr("ReadOnly", true);;
})
</script>
</body>
</html>
0
Tanggapan
coba jelaskan pertanyannya di atas, jangan cuma naro kode gan, biar jelas
Udah saya edit mas.. Mohon dibantu ya.
1 Jawaban:
Klo modals nya ditampilkan di client side, maka statusnya akan kembali "Hide" ketika postback. Untuk tetap tampil, maka di event ddl text_changed, modals nya di set visible lagi.
0