I'm using a bootstrap modal to save and update some sort of events. My asp code is:
<asp:UpdatePanel ID="upModal" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" id="myModal" aria-labelledby="myLargeModalLabel">
<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="gridSystemModalLabel">Add event:</h4>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<div class="row">
<div class="col-md-12">
<h4>Date:</h4>
</div>
<div class="col-md-12">
<asp:TextBox ID="TextBoxDate" runat="server" Width="100" CssClass="rbl"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" ImageUrl="~/calendar.png" CssClass="rbl" runat="server" Height="20" Width="20" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender2" TargetControlID="TextBoxDate" runat="server" PopupButtonID="ImageButton2" Format="dd/MM/yyyy" />
</div>
</div>
</div>
<div class="col-md-3">
<div class="row">
<div class="col-md-12">
<h4>List</h4>
</div>
<div class="col-md-12">
<asp:ListBox ID="ListBoxEgk" runat="server"></asp:ListBox>
</div>
</div>
</div>
<div class="col-md-3">
<div class="row">
<div class="col-md-12">
<h4>info from:</h4>
</div>
<div class="col-md-12">
<asp:TextBox ID="name" runat="server"></asp:TextBox>
</div>
<div class="col-md-12">
<h4>to:</h4>
</div>
<div class="col-md-12">
<asp:ListBox ID="ListBoxEpik" runat="server"></asp:ListBox>
</div>
</div>
</div>
<div class="col-md-3">
<div class="row">
<div class="col-md-12">
<h4>Kind of event:</h4>
</div>
<div class="col-md-12">
<asp:ListBox ID="ListBoxEidosSum" runat="server"></asp:ListBox>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-5">
<div class="col-md-12">
<h4>Event desc:</h4>
</div>
<div class="col-md-12">
<asp:TextBox ID="TextBoxSumvan" runat="server" Height="210px" MaxLength="500" Rows="12" Width="380px" TextMode="MultiLine"></asp:TextBox>
</div>
</div>
<div class="col-md-5">
<div class="col-md-12">
<h4>Actions:</h4>
</div>
<div class="col-md-12">
<asp:TextBox ID="TextBoxE" runat="server" Height="210px" MaxLength="500" Rows="12" Width="380px" TextMode="MultiLine"></asp:TextBox>
</div>
</div>
<div class="col-md-2">
<div class="col-md-12">
<h4>Given to:</h4>
</div>
<div class="col-md-12">
<asp:ListBox ID="ListBoxUsers" runat="server"></asp:ListBox>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button ID="cancelBtn" CssClass="btn btn-default" runat="server" data-dismiss="modal" Text="Ακύρωση" OnClick="cancelBtn_Click" />
<asp:Button ID="saveBtn" runat="server" Text="Αποθήκευση" CssClass="btn btn-primary" OnClick="Btn_save_Click" />
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I'm "calling" this modal by:
img ID="addEvent" src="/very-basic-plus-icon.png" data-toggle="modal" data-target=".bs-example-modal-lg" Height="20" Width="20" />
and it works. The modal is showing up and before I used <asp:Updatepanel> it was working perfect but I want to be able to pick events from a grid and show the this modal, update them if i have to etc. The image button bellow is calling a method from behind
<asp:ImageButton ID="imgEdit" ImageUrl="~/edit.png" runat="server" OnClick="imgEdit_Click" />
and what's running from behind is:
static Boolean indexY = false;
static newEvent event4Update = new newEvent();
protected void imgEdit_Click(object sender, ImageClickEventArgs e)
{
GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
int index = gvRow.RowIndex;
var item = searchEvents.ElementAt(index);
CMMS_IServiceClient client = new CMMS_IServiceClient();
event4Update = client.returnRowForUpdate(item.RowId);
client.Close();
TextBoxDate.Text = Convert.ToString(event4Update.ImerominiaSumvantos);
name.Text = event4Update.Name;
ListBoxEgk.SelectedValue = event4Update.From;
ListBoxEpik.SelectedValue = event4Update.TroposEpikoinwnias;
UserListBox.SelectedValue = event4Update.AssignmentTo;
TextBoxSumvan.Text = event4Update.Sumvan;
ListBoxEidosSum.SelectedValue = event4Update.TypeOfEvent;
TextBoxEnergeies.Text = event4Update.Actions;
ListBoxUsers.SelectedValue = event4Update.To;
indexY = true;
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
upModal.Update();
}
Atm my modal is working perfect. Everything is loaded and I can edit but when I press save which is inside my modal there are problems.
protected void Btn_save_Click(object sender, EventArgs e)
{
CMMS_IServiceClient client = new CMMS_IServiceClient();
if (ListBoxEgk.SelectedValue.ToString() == "" ||
ListBoxEpik.SelectedValue.ToString() == "" ||
TextBoxSumvan.Text == "" ||
ListBoxEidosSum.SelectedValue.ToString() == "")
{
Page.ClientScript.RegisterStartupScript(GetType(), "Scripts", "<script>alert('Some field is empty.');</script>");
}
else
{
if (indexY == true)
{
IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);
newEvent updateEvent = new newEvent();
updateEvent.RowId = event4Update.RowId;
updateEvent.ImerominiaSumvantos = DateTime.Parse(TextBoxDate.Text, culture, System.Globalization.DateTimeStyles.AssumeLocal);
updateEvent.Name = name.Text;
updateEvent.From = ListBoxEgk.SelectedValue.ToString();
updateEvent.TroposEpikoinwnias = ListBoxEpik.SelectedValue.ToString();
updateEvent.To = UserListBox.SelectedValue.ToString();
updateEvent.Sumvan = TextBoxSumvan.Text;
updateEvent.TypeOfEvent = ListBoxEidosSum.SelectedValue.ToString();
updateEvent.Actions = TextBoxEnergeies.Text;
updateEvent.AssignmentTo = ListBoxUsers.SelectedValue.ToString();
updateEvent.EventState = (TextBoxEnergeies.Text != "") ? true : false;
client.updateRow(updateEvent);
indexY = false;
event4Update = null;
}
else
{
IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);
newEvent addEvent = new newEvent();
addEvent.ImerominiaSumvantos = DateTime.Parse(TextBoxDate.Text, culture, System.Globalization.DateTimeStyles.AssumeLocal);
addEvent.Name = name.Text;
addEvent.From = ListBoxEgk.SelectedValue.ToString();
addEvent.TroposEpikoinwnias = ListBoxEpik.SelectedValue.ToString();
addEvent.To = UserListBox.SelectedValue.ToString();
addEvent.Sumvan = TextBoxSumvan.Text;
addEvent.TypeOfEvent = ListBoxEidosSum.SelectedValue.ToString();
addEvent.Actions = TextBoxEnergeies.Text;
addEvent.AssignmentTo = ListBoxUsers.SelectedValue.ToString();
addEvent.EventState = (TextBoxEnergeies.Text != "") ? true : false;
client.write(addEvent);
}
client.Close();
ListBoxEgk.ClearSelection();
ListBoxEidosSum.ClearSelection();
ListBoxEpik.ClearSelection();
name.Text = "";
TextBoxEnergeies.Text = "";
TextBoxSumvan.Text = "";
TextBoxDate.Text = "";
ListBoxUsers.ClearSelection();
searchBtn_Click(sender, e);
//ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal();", true);
//upModal.Update();
}
}
The code is also a huge mess, if anyone can suggest better ways to work with the monster i made please let me know.
Your save button has nothing to dismiss the modal. And I suspect your cancel button's data-dismiss attribute may be interering with the postback mechanism.
Try this:
<asp:Button ID="cancelBtn" CssClass="btn btn-default" runat="server" Text="Ακύρωση" OnClientClick="dismissModal();" OnClick="cancelBtn_Click" />
<asp:Button ID="saveBtn" runat="server" Text="Αποθήκευση" CssClass="btn btn-primary" OnClick="Btn_save_Click" OnClientClick="dismissModal();" />
function dismissModal() {
$('#myModal').modal('hide');
}
The OnClientClick client side method will run, then a postback will occur and your OnClick server side functions will run.
Related
I have a button that makes a call to an external url to log in to an accounting program (Xero) using OAuth 2. After receiving the token, etc., the button is hidden and a "Disconnect" button is shown. When the disconnect button is clicked, it is then hidden and the Connect button is displayed again. The problem is if I click the "Connect" button again, on postback it executes the code for the "Disconnect" button again, so I can never repeat the first cycle. The "Connect" button stays and all of the disconnect code runs again. I have tried to capture the postback being called by the first button, so that I could tell the disconnect code not to run again, but it is always null. Even worse, the postback always shows that the "Disconnect" button caused the postback even though it is no longer visible on the page. I do not understand why it is doing this. Both buttons are inside an "Update Panel" so that I can hide/show them.
Here is the button code:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<div class="row" id="XeroNotConnected2" runat="server" visible="false">
<div class="col-sm-12 col-md-6">
<div class="form-group">
<label for="imgXero" class="col-sm-3 control-label"></label>
<div class="col-sm-9">
<asp:ImageButton runat="server" ID="imgXero" ImageUrl="~/assets/img/icons/connect-white.svg" OnClick="btnXeroConnect_Click" UseSubmitBehavior="False" />
</div>
</div>
</div>
</div>
<div id="XeroConnected" runat="server" visible="false">
<div class="row" >
<div class="col-sm-12 col-md-6">
<div class="form-group">
<label for="ddlTenants" class="col-sm-3 control-label">Select an Organization:</label>
<div class="col-sm-9">
<asp:DropDownList runat="server" ID="ddlTenants" CssClass="form-control" AutoPostBack="true" OnSelectedIndexChanged="ddlTenants_SelectedIndexChanged"></asp:DropDownList>
</div>
</div>
</div>
</div>
</div>
<div id="XeroConnected2" runat="server" visible="false">
<div class="row">
<div class="col-sm-12 col-md-6">
<div class="form-group">
<label for="btnDisconnect" class="col-sm-3 control-label"></label>
<div class="col-sm-9">
<button type="button" runat="server" class="btn btn-alt3" id="btnDisconnect" onclick="javascript:OpenModal('disconnectConfirm')"><i class="icon s7-plug"></i> Disconnect Xero</button>
</div>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
In Page_Load I have:
if(IsPostBack)
{
Control pbControl = GetControlThatCausedPostBack(this.Page);
if (pbControl != null)
{
if (pbControl.ID == "lnkDelete")
{
InitiateConnect = false;
}
}
}
Method used to get Control that caused postback is:
private Control GetControlThatCausedPostBack(Page page)
{
LoggerBA.Log(DB_Context, Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"]), MethodBase.GetCurrentMethod().Name, UtilityBA.LoggerLevel.Debug, "method");
//initialize a control and set it to null
Control ctrl = null;
//get the event target name and find the control
string ctrlName = page.Request.Params.Get("__EVENTTARGET");
if (!String.IsNullOrEmpty(ctrlName))
ctrl = page.FindControl(ctrlName);
//return the control to the calling method
return ctrl;
}
Code in disconnect button is:
protected void lnkDelete_Click(object sender, EventArgs e)
{
if(InitiateConnect == false)
{
InitiateConnect = true;
PageAsyncTask t = new PageAsyncTask(DisconnectTenant);
Page.RegisterAsyncTask(t);
Page.ExecuteRegisteredAsyncTasks();
Session.Remove("OAuthToken");
Session.Remove("xeroToken");
Session.Remove("Tenants");
Session.Remove("xeroTenant");
XeroConnected.Visible = false;
XeroConnected2.Visible = false;
btnDisconnect.Disabled = true;
XeroNotConnected2.Visible = true;
XeroNotConnected1.Visible = true;
}
}
Any assistance is greatly appreciated.
I have a form AdminHome.aspx. When a user signed in, then on AdminHome.aspx page Load Event, That users profile data loaded from database and populate corresponding Textboxes. I have a Button control for Update User Information. When a User logged in, this is how its Home Page looks like. Here is the picture .
Now when i change the Designation from INTERN to Trainee. Here is the picture
and click on Update My Profile Button. It shows no Errors or Exceptions, instead it display a message Record Update Successfully. But when i check it in the database, it wasn't updated. After putting it on debug mood, i came to know that its taking the older values from Textboxes, I mean i change the value of Designation from INTERN to TRAINEE but still its taking INTERN. Here is the picture
Following is my update Button Code
protected void btnUpdateProfile_Click(object sender, EventArgs e)
{
try
{
UpdateUser();
}
catch (Exception ex)
{
ShowNotification("Error: " + ex + "", WarningType.Danger);
}
}
private void UpdateUser()
{
using (SqlConnection con = new SqlConnection(Base.GetConnection))
{
using (SqlCommand cmd = new SqlCommand("UPDATE TableUserProfile SET UserName=#UserName,UserContact=#UserContact,UserDesignation=#UserDesignation,UserDepartment=UserDepartment WHERE UserEmpNum=#UserEmpNum", con))
{
string Uname, UContact, UDesignation, UDepartment, UEmployeeNo;
Uname = tbName.Value.ToUpper();
UContact = tbMobileNo.Value.ToUpper();
UDesignation = tbDesignation.Value.ToUpper();
UDepartment = tbDepartment.Value.ToUpper();
UEmployeeNo = tbEmployeeNo.Value.ToUpper();
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("#UserName", Uname);
cmd.Parameters.AddWithValue("#UserContact", UContact);
cmd.Parameters.AddWithValue("#UserDesignation", UDesignation);
cmd.Parameters.AddWithValue("#UserDepartment", UDepartment);
cmd.Parameters.AddWithValue("#UserEmpNum", UEmployeeNo);
con.Open();
cmd.ExecuteNonQuery();
ShowNotification("Succes: Record Saved Succesfully!", WarningType.Success);
}
}
}
and here is the .aspx code.
<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-10">
<h4>Your Profile</h4>
<hr />
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group row">
<label for="username" class="col-4 col-form-label">Name*</label>
<div class="col-6">
<input runat="server" id="tbName" class="form-control here" required="required" type="text" />
</div>
</div>
<div class="form-group row">
<label for="name" class="col-4 col-form-label">Mobile Number</label>
<div class="col-6">
<input runat="server" id="tbMobileNo" class="form-control here" type="text" />
</div>
</div>
<div class="form-group row">
<label for="lastname" class="col-4 col-form-label">Employee Number</label>
<div class="col-6">
<input runat="server" id="tbEmployeeNo" class="form-control here" readonly="True" type="text" aria-readonly="True" aria-disabled="True" />
</div>
</div>
<div class="form-group row">
<label for="text" class="col-4 col-form-label">Designation</label>
<div class="col-6">
<input runat="server" id="tbDesignation" class="form-control here" required="required" type="text" />
</div>
</div>
<div class="form-group row">
<label for="text" class="col-4 col-form-label">Department</label>
<div class="col-6">
<input runat="server" id="tbDepartment" class="form-control here" required="required" type="text" />
</div>
</div>
<div class="form-group row">
<div class="offset-4 col-8">
<asp:Button runat="server" ID="btnUpdateProfile" Text="Update My Profile" class="btn btn-primary" OnClick="btnUpdateProfile_Click"></asp:Button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</asp:Content>
Here is the PageLoad code.
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserEmployee"] != null)
{
userEmployeeNumber = Convert.ToString(Session["UserEmployee"]);
GetUserData();
ShowNotification("Welcome! Mr/Mrs " + EmployeeID.UserName.ToString() + "", WarningType.Success);
}
}
private void GetUserData()
{
using (SqlConnection con = new SqlConnection(Base.GetConnection))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT [UserName],[UserContact],[UserEmpNum],[UserDesignation],[UserDepartment] FROM TableUserProfile WHERE UserEmpNum=#UserEmpNum", con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("UserEmpNum", userEmployeeNumber);
SqlDataReader r = cmd.ExecuteReader();
while (r.Read())
{
tbName.Value = r["UserName"].ToString();
EmployeeID.UserName = tbName.Value.ToString();
tbMobileNo.Value = r["UserContact"].ToString();
tbEmployeeNo.Value = r["UserEmpNum"].ToString();
tbDesignation.Value = r["UserDesignation"].ToString();
tbDepartment.Value = r["UserDepartment"].ToString();
}
}
}
}
In your Page_Load, you have to check IsPostBack
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
if (Session["UserEmployee"] != null)
{
userEmployeeNumber = Convert.ToString(Session["UserEmployee"]);
GetUserData();
ShowNotification("Welcome! Mr/Mrs " + EmployeeID.UserName.ToString() + "", WarningType.Success);
}
}
}
Otherwise in each pageload, your textbox data gets updated with DB value
I use boostrap modals for saving data on an ASP.NET Web page and I'm having an issue when users by mistake clicks more than once the "Save" button on the modal. The event fires the number of times the user presses the click. This happens because the modal doesn't closes immediatly. It takes about 1 second to close, enough for the user to click more than once the button.
My database is validated (I'm using Entity Framework) so, there's no duplicate values inserted. But if the user clicks two times, it tries to insert the record two times, and the error message is displayed.
How can I prevent this?
This is the modal code:
<asp:Panel runat="server" ID="pnlBank" DefaultButton="btnSaveBank">
<div class="modal fade" id="modBank" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4 class="modal-title">Banco</h4>
</div>
<div class="modal-body">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<div class="form-group">
<div class="row">
<label class="col-md-2 control-label">Name</label>
<div class="col-md-10">
<asp:TextBox ID="txtBankName" CssClass="form-control" runat="server" MaxLength="150"></asp:TextBox>
</div>
</div>
<label class="col-md-2 control-label">Address</label>
<div class="col-md-10">
<asp:TextBox ID="txtBankAddress" CssClass="form-control" runat="server" MaxLength="150"></asp:TextBox>
</div>
</div>
<div class="row">
<label class="col-md-2 control-label">Phone</label>
<div class="col-md-10">
<asp:TextBox ID="txtBankPhone" CssClass="form-control" runat="server" MaxLength="15"></asp:TextBox>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="modal-footer">
Cerrar
<asp:Button ID="btnSaveBank" runat="server" Text="Save" CssClass="btn btn-primary" OnClick="btnSaveBank_Click" />
</div>
</div>
</div>
</div>
</asp:Panel>
And this is the code behind:
protected void btnSaveBank_Click(object sender, EventArgs e)
{
Bank newBank = new Bank();
newBank.Name = txtBankName.Text;
newBank.Address = txtBankAddress.Text;
newBank.Phone = txtBankPhone.Text;
using (bankEntity)
{
try
{
bankEntity.Bank.Add(newBank);
bankEntity.SaveChanges();
lblResult.Text = "Bank successfully saved";
ObtenerBancos();
}
catch (Exception ex)
{
lblResult.Text = "Error when saving bank: " + ex.Message;
}
}
}
You can try disabling the save button and closing the modal via jQuery and once the modal is closed you can re-enable the save button again using jQuery. Just make sure that the jQuery event handlers are defined after btnSaveBank_Click so that btnSaveBank_Click takes precedence over the close/hide trickery:
$(document).ready(function () {
$("#btnSaveBank").click(function() {
$(this).prop("disabled", true);
$("#modBank").modal("hide");
});
$("#modBank").on("hidden.bs.modal", function() {
$("#btnSaveBank").prop("disabled", false);
});
});
I am using Bootstrap carousel slider script inside Repeater but its not working proper.The data display at once and stack horizontal ,When I click NEXT or PREVIOUS in the carousel control, the carousel displays correctly but with only one item in every carousel i want to display 3 items in each carousel .
<!-- Begin Carousel -->
<div class="row">
<div id="realto-carousel-afee" class="carousel slide">
<div class="carousel-navigation pull-right"> <a class="serif italic pull-left view-all-carousel" href="properties-grid-layout-2">عرض الكل</a> <a class="left carousel-control pull-left" href="#realto-carousel-afee" data-slide="prev"><i class="fa fa-angle-left"></i></a> <a class="right carousel-control pull-right" href="#realto-carousel-afee" data-slide="next"><i class="fa fa-angle-right"></i></a> </div>
<div class="carousel-inner">
<asp:Repeater runat="server" ID="ProjectsRepater">
<ItemTemplate>
<div <%# Container.ItemIndex == 0 ? "active" : "" %>>
<div class="col-lg-4 col-md-4 col-sm-4 col-sx-12">
<div class="box-container">
<div class="holder"> <a class="overlay" href="" title=""> <span class="more"> <i class="fa fa-zoom-in"></i> </span>
<div class="prop_img"> <img width="370" height="210" src="150w" sizes="(max-width: 370px) 100vw, 370px" /> </div>
</a> <span class="prop-tag">للبيع</span>
<div class="prop-info">
<h3 class="prop-title">
<asp:Label ID="ProjId" runat="server" Visible="false" Text='<%# Eval("ID")%>'></asp:Label>
<asp:Label Text='<%# Eval("ProjectName")%>' ID="lblProjName" runat="server">مشروع 94 حي اللوتس الشمالية 2</asp:Label>
</h3>
<ul class="more-info clearfix">
<li class="info-label clearfix"> <span class="pull-left" style="float:right !important">المساحات</span>
<label id="lblArea" runat="server" class="qty pull-right">2</label>
</li>
<li class="info-label clearfix"> <span class="pull-left" style="float:right !important">نظام السداد</span> <span id="lblPaymentsSystem" runat="server" class="qty pull-right">2</span> </li>
<li class="info-label clearfix"> <span class="pull-left" style="float:right !important">تاريخ الاستلام</span> <span id="lblReceivedDate" runat="server" class="qty pull-right">2</span> </li>
</ul>
</div>
<!-- prop-info -->
</div>
<!-- holder -->
</div>
<!-- box-container -->
</div>
</div>
</ItemTemplate>
</asp:Repeater>
<!-- .carousel-inner -->
</div>
</div>
<!--End Carousel-->
</div>
in this code i select all projects and display them in repeater control by carousel slider
protected void Page_Load(object sender, EventArgs e)
{
// RepeterData();
ProjectsRepater.DataSource = GetAllProjecct();
ProjectsRepater.DataBind();
}
public class Proj
{
public int ID { get; set; }
public string ProjectName { get; set; }
}
public List<Proj> GetAllProjecct()
{
List<Proj> listproj = new List<Proj>();
SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["AlamarConnectionString"].ConnectionString);
SqlCommand com = new SqlCommand("Select ID,ProjectName from Projects", con);
con.Open();
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
Proj cnt = new Proj();
cnt.ID = Convert.ToInt32(reader["ID"]);
cnt.ProjectName = Convert.ToString(reader["ProjectName"]);
listproj.Add(cnt);
}
return listproj;
}
I have the following code:
<asp:Button ID="btnDelete" runat="server" Text="Delete Report" OnClientClick="return confirm ('This will delete the report. Continue?');" />
Once the user clicks on OK how do I get the server side script to fire that actually deletes.
I had
OnClick="btnDelete_Click"
on the above code but nothing
happened.
Open your code behind and add
public void btnDelete_Click(object sender, EventArgs e)
{
//Your logic here
}
You can use bootstrap's modal.
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="showDialog_Event" />
Page:
<div class="container">
<div id="modalDialog" class="modal" role="dialog">
<div class="modal-dialog modal-sm" data-backdrop="static">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title text-center">
<h4>Message</h4>
</div>
</div>
<div id="modalBodyDialog" class="modal-body">
</div>
<div class="modal-footer">
<asp:Button runat="server" ID="btnOkDialog" CssClass="btn btn-default" Text="Ok" OnClick="btnOkDialog_Click" />
<input type="button" value="Cancel" data-dismiss="modal" />
</div>
</div>
</div>
</div>
Code:
public void showDialog_Event(object sender, EventArgs e) {
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(#"<script type='text/javascript'>");
sb.Append("$('#modalDialog').modal({'backdrop': 'static', 'keyboard': 'static', 'show': true});");
sb.Append("$('#modalBodyDialog').html('<ul><li>");
sb.Append(message);
sb.Append("</li></ul>')");
sb.Append(#"</script>");
Page.ClientScript.RegisterStartupScript(this.GetType(), "ModalScript", sb.ToString(), false);
}
Get event confirm (btn OK)
public void btnOkDialog(object sender, EventArgs e) {
// your code for delete
}
This example need bootstrap and jquery.