I'm using master page for my web application there is a content page we can call it Banks data has a GridView displays all banks and has an Edit,Add,Delete buttons
I wand display a bootstrap modal with input data to edit or add new bank and to validate using asp RequiredFieldValidator
this is the ASPX Code
<Columns>
<asp:BoundField DataField="bankCode" HeaderText="Bank Code" />
<asp:BoundField DataField="bankName" HeaderText="Bank Name" />
<asp:TemplateField >
<ItemTemplate >
<asp:LinkButton ID="lb_Edit" runat="server" CssClass="btn btn-sm btn-default" data-toggle="modal" data-target="#AddBankModal" CommandName="BankEdit" CommandArgument='<%#Eval("bankCode") %>' OnClick="lb_Edit_Click"><strong>Edit</strong></asp:LinkButton>
<asp:LinkButton ID="LB_Delete" runat="server" CssClass="btn btn-sm btn-danger" CommandName="BankDelete" CommandArgument='<%#Eval("bankCode") %>'><strong>Delete</strong></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle Height="15px" HorizontalAlign="Right" VerticalAlign="Middle" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" SelectCommand="SELECT [bankCode], [bankNameAr], [bankNameEng] FROM [Bank]"></asp:SqlDataSource>
<!-- Modal -->
<div id="AddBankModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" >
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" style="text-align:right">Bank Data </h4>
</div>
<div class="modal-body">
<asp:Label ID="lblBankCode" runat="server" Text="Bank Code" CssClass="label" style="text-align:right;font-weight:bold"></asp:Label>
<asp:TextBox ID="txtBankCode" runat="server" CssClass="form-control"></asp:TextBox>
<asp:Label ID="lblBankNameAr" runat="server" Text="Bank Name" CssClass="label" style="text-align:right;font-weight:bold"></asp:Label>
<asp:TextBox ID="txtBankNameAr" runat="server" CssClass="form-control"></asp:TextBox>
<div class="row" >
<div class="col-lg-12">
<asp:Button ID="btnUpdateBank" runat="server" Text="Save Data" CssClass="btn btn-outline btn-primary" style="width:100px" OnClick="btnUpdateBank_Click" />
<button type="button" class="btn btn-outline btn-primary" data-dismiss="modal" style="width:100px">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
Does any one have any Ideas to do this using ASP code behind without using Jquery
May be you need some thing like this.Remember two things
1.Dont forget to add ClientIDMode="Static" to asp.net control
2.Postback is prevented by e.preventDefault() to add jQuery functionality in click event
<asp:GridView ID="GridView1" runat="server" ClientIDMode="Static">
<Columns>
<asp:TemplateField >
<ItemTemplate >
<asp:LinkButton ID="lb_Edit" runat="server" CssClass="btn btn-sm btn-default" data-toggle="modal" data-target="#AddBankModal" ClientIDMode="Static"><strong>Edit</strong>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div id="AddBankModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
×</button>
<h4 class="modal-title" style="text-align: right">
Bank Data
</h4>
</div>
<div class="modal-body">
<asp:Label ID="lblBankCode" runat="server" Text="Bank Code" CssClass="label" Style="text-align: right;
font-weight: bold"></asp:Label>
<asp:TextBox ID="txtBankCode" runat="server" CssClass="form-control"></asp:TextBox>
<asp:Label ID="lblBankNameAr" runat="server" Text="Bank Name" CssClass="label" Style="text-align: right;
font-weight: bold"></asp:Label>
<asp:TextBox ID="txtBankNameAr" runat="server" CssClass="form-control"></asp:TextBox>
<div class="row">
<div class="col-lg-12">
<asp:Button ID="btnUpdateBank" runat="server" Text="Save Data" ClientIDMode="Static" CssClass="btn btn-outline btn-primary"
Style="width: 100px" />
<button type="button" class="btn btn-outline btn-primary" data-dismiss="modal" style="width: 100px">
Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(function () {
$('.btn').on('click', function (e) {
e.preventDefault();
var buttonid = $(this).attr('id');
console.log(buttonid);
if (buttonid == "lb_Edit") {
$('#AddBankModal').modal({
show: true,
backdrop: 'static'
});
}
if (buttonid == "btnUpdateBank") {
//
alert('Do some ajax to send data to Backend');
}
//currentRow.remove();
});
})
</script>
Related
I had written code for modal popup but its not working, I am new to .net so i don't know how its work so please help me in that.. On clicking add button i want to open modal popup but its not working.
<script type="text/javascript">
$(function () {
$("#btn_add_new").click(function () {
$('#UsersModal').modal('show');
});
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Button ID="btn_add_new" runat="server" Text="Add New" CausesValidation="False" CssClass="button" data-target="#UsersModal"
/>
<div class="modal fade" id="UsersModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×</button>
<h4 class="modal-title" id="ModalTitle">
New User</h4>
</div>
<div class="modal-body">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="col-sm-3">
<asp:Label ID="lbluname" Font-Size="Large" runat="server" Text="Username"></asp:Label>
</div>
<div class="col-sm-5">
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</div>
<br />
<div class="col-sm-3">
<asp:Label ID="Label1" Font-Size="Large" runat="server" Text="Username"></asp:Label>
</div>
<div class="col-sm-5">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
<asp:CheckBox ID="chkRememberMe" Text="Remember Me" runat="server" />
<asp:Button ID="Button2" runat="server" CssClass="btn btn-primary" Text="Save" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
</asp:Content>
You could just use a html button like this:
<button type="button" class="btn btn-primary" CssClass="button"
data-toggle="modal" data-target="#UsersModal">Add New</button>
Your javascript is not required to open the modal.
The modal opens fine on my test page using your modal code.
Pretty new to asp.net. So I just wanted to have multiple modals on my page, like I can do it in HTML. But the problem here is, that the first modal of the code works fine. But the second modal triggers on submit all of the RequiredFieldValidators of the first modal, and doesn't fire it's own function on the code behind (eventEintragen()). The function exists thats for sure.
I searched trough my whole code and checked every call. It has to be a problem with the modals itself, i'm guessing I missunderstood smth about asp.net and got both of the modals in conflict with each others. I would be gratefull for some help... Of course I looked into some other questions, but as you can guess, it's pretty hard to find someone with the same conflict problem.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="container">
<div class="row">
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Event erstellen
</button>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!--Modal-->
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<asp:ValidationSummary runat="server" CssClass="text-danger" />
<div class="form-group">
<asp:TextBox runat="server" ID="Wettkampfname" placeholder="Wettkampfname" CssClass="form-control" TextMode="SingleLine" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Wettkampfname" CssClass="text-danger" ErrorMessage="Bitte Wettkampfname eingeben." />
</div>
<div class="form-group">
<asp:TextBox runat="server" ID="Teilnehmeranzahl" placeholder="Teilnehmeranzahl" CssClass="form-control" TextMode="SingleLine" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Teilnehmeranzahl" CssClass="text-danger" ErrorMessage="Bitte Wettkampfname." />
<asp:CompareValidator runat="server" Operator="DataTypeCheck" CssClass="text-danger" Type="Integer" ControlToValidate="Teilnehmeranzahl" ErrorMessage="Die Anzahl muss eine Zahl sein" />
</div>
<div class="form-group">
<asp:TextBox runat="server" ID="Strasse" placeholder="Strasse" CssClass="form-control" TextMode="SingleLine" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Strasse" CssClass="text-danger" ErrorMessage="Bitte Strasse eingeben." />
</div>
<div class="form-group">
<asp:TextBox runat="server" ID="Ort" placeholder="Ort" CssClass="form-control" TextMode="SingleLine" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Ort" CssClass="text-danger" ErrorMessage="Bitte Strasse eingeben." />
</div>
<div class="form-group">
<asp:TextBox runat="server" ID="Hausnummer" placeholder="Hausnummer" CssClass="form-control" TextMode="SingleLine" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Hausnummer" CssClass="text-danger" ErrorMessage="Bitte Hausnummer eingeben." />
<asp:CompareValidator runat="server" Operator="DataTypeCheck" CssClass="text-danger" Type="Integer" ControlToValidate="Hausnummer" ErrorMessage="Die Hausnummer muss eine Zahl sein" />
</div>
<div class="form-group">
<asp:TextBox runat="server" ID="Zeit" placeholder="Zeit (hh:mm)" CssClass="form-control" TextMode="SingleLine" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Zeit" CssClass="text-danger" ErrorMessage="Bitte Strasse eingeben." />
<asp:RegularExpressionValidator CssClass="text-danger" runat="server" ErrorMessage="Zeit Format in hh:mm" ValidationExpression="^(0[0-9]|1[0-9]|2[0-3]|[0-9]):[0-5][0-9]$" ControlToValidate="Zeit" />
</div>
<div class="form-group">
<asp:TextBox runat="server" ID="Datum" placeholder="Datum" CssClass="form-control" TextMode="Date" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Datum" CssClass="text-danger" ErrorMessage="Bitte Strasse eingeben." />
</div>
</div>
<div class="modal-footer">
<asp:Button Text="Save" OnClick="eventErstellen" runat="server" CssClass="btn btn-primary"/>
<asp:Button Text="Close" OnClick="Submit" runat="server" data-dismiss="modal" CssClass="btn btn-secondary"/>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
<div class="container">
<div class="row">
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#mySecondModal">
Für Event eintragen
</button>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<!--Modal-->
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
<div class="modal fade" id="mySecondModal" tabindex="-1" role="dialog" aria-labelledby="mySecondModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<asp:DropDownList ID="ddlSubject" runat="server" AppendDataBoundItems="true">
<asp:ListItem Text="<Select Subject>" Value="0" />
</asp:DropDownList>
</div>
<div class="modal-footer">
<asp:Button Text="Save" OnClick="eventEintragen" runat="server" CssClass="btn btn-primary"/>
<asp:Button Text="Close" OnClick="Submit" runat="server" data-dismiss="modal" CssClass="btn btn-secondary"/>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
I am having a strange problem and have spent the majority of the last 4 working hours trying to figure this out. I have read most of the similar questions on here but they are either not working due to a div mismatch or are wanting to open one modal from another.
I have a gridview containing data records with 3 link buttons in a template field. 2 of these buttons need to call up a modal where the user can either view more details or cancel the record.
The problem I am facing is that whichever modals code I put first in the aspx page, that modal displays correctly. Any modals after that only displays the black overlay.
I have read somewhere that this may be due to the z-index but I have not been able to get this working. Any guidance will be appreciated.
Gridview Markup:
<asp:GridView ID="gvEnquiries" runat="server" CssClass="table table-hover table-striped" GridLines="None" AutoGenerateColumns="False" DataKeyNames="EnquiryID">
<Columns>
<asp:BoundField HeaderText="EnquiryID" DataField="EnquiryID" Visible="false" />
<asp:BoundField HeaderText="Enquiry No" DataField="EnquiryNo" />
<asp:BoundField DataField="EType" />
<asp:BoundField HeaderText="Company" DataField="Company" />
<asp:BoundField HeaderText="Description" DataField="Description" />
<asp:BoundField HeaderText="Assigned To" DataField="AssignedTo" />
<asp:BoundField HeaderText="Address By" DataField="AddressBy" DataFormatString="{0:dd MMM yyyy}" />
<asp:BoundField HeaderText="Enquiry Date" DataField="EnquiryDate" DataFormatString="{0:dd MMM yyyy}" />
<asp:TemplateField>
<ItemTemplate>
<div class="btn-group pull-right">
<asp:LinkButton CssClass="btn btn-info" ID="btnView" runat="server" data-toggle="tooltip" data-placement="bottom" ToolTip="View Details" OnClick="btnView_Click"><span class="glyphicon glyphicon-eye-open"></span></asp:LinkButton>
<asp:LinkButton CssClass="btn btn-info" ID="LinkButton1" runat="server" data-toggle="tooltip" data-placement="bottom" ToolTip="Create Quote"><span class="glyphicon glyphicon-credit-card"></span></asp:LinkButton>
<asp:LinkButton CssClass="btn btn-info" ID="btnCloseEnq" runat="server" data-toggle="tooltip" data-placement="bottom" ToolTip="Close Enquiry" OnClick="btnCloseEnq_Click"><span class="glyphicon glyphicon-ban-circle"></span></asp:LinkButton>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The modals are being called from code side using the following line of code, obviously changing the ID for the seperate calls:
ScriptManager.RegisterStartupScript(this, this.GetType(), "none", "<script>$('#CloseEnq').modal('show');</script>", false);
The actual markup for the 2 modals are:
<div class="modal fade" id="ViewEnqDetail" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-mid modal-dialog">
<div class="modal-content">
<asp:UpdatePanel ID="updViewEnqModal" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">
<asp:Label runat="server" ID="lblViewEnqTitle"></asp:Label></h4>
</div>
<div class="modal-body">
<div class="container-fluid">
****Body Content In Here*******
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="modal-footer">
<button class="btn btn-info" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
</div>
and
<div class="modal fade" id="CloseEnq" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-mid modal-dialog">
<div class="modal-content">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">
<asp:Label runat="server" ID="Label1"></asp:Label></h4>
</div>
<div class="modal-body">
<div class="container-fluid">
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="modal-footer">
<button class="btn btn-info" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
</div>
After another 7 hours I have finally found the culprit.
The order in which the tags were closed were incorrect. The body div was only being closed after the update panel and its content div was.
I am trying to show pop-up on clicking Button named "Lunch Break", it works fine when am using normal Bootstrap button button control.
But i want use asp:Button control to show same pop-up but pop-up does appears on clicking on that button, it just refresh the page.
aspx code :
<asp:Button ID="btnLunchBreak" runat="server" Text="Lunch Break" CssClass="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" />
<div class="modal fade panel panel-primary" id="myModal" tabindex="-1" runat="server" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false" >
<div class="modal-dialog panel panel-primary ">
<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>
<h2 class="modal-title" id="gridSystemModalLabel" style="color: red">Lunch Break</h2>
</div>
<div class="modal-body">
<div class="container-fluid">
<br />
<br />
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
<asp:Button ID="btnLunchStart" runat="server" CssClass="btn btn-success" Text="Start" OnClick="btnLunchStart_Click" />
<asp:Button ID="btnLunchStop" runat="server" CssClass="btn btn-success" Text="Stop" OnClick="btnLunchStop_Click" />
</div>
<div class="col-md-4"></div>
</div>
<div class="col-md-4"></div>
<div class="col-md-4">
<asp:Label ID="lbl_LTimer" runat="server" CssClass="h3" ForeColor="Blue"></asp:Label><br />
<asp:Label ID="lbl_Lhour" runat="server" Visible="false" CssClass="h4" ForeColor="Black" Text="Hr :"></asp:Label>
<asp:Label ID="lbl_LMin" runat="server" Visible="false" CssClass="h4" ForeColor="Black" Text="Min :"></asp:Label>
<asp:Label ID="lbl_LSec" runat="server" Visible="false" CssClass="h4" ForeColor="Black" Text="sec"></asp:Label>
<br />
<asp:Label ID="lbl_LHr" runat="server" CssClass="h3" Font-Bold="true" Font-Size="20" ForeColor="red"></asp:Label>
<br />
<br /> <br /><br /><br /><br /><br />
<asp:Label ID="lbl_Lbrkresp" runat="server" Visible="false"></asp:Label>
<asp:Timer ID="Timer3" runat="server" Interval="1000000" OnTick="Timer3_Tick">
</asp:Timer>
</div>
<div class="col-md-4"></div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
am not familiar with bootstrap may be am doing it in wrong way. Suggest any solution
You can try to set the attribute UseSubmitBehavior to false.
Thus, ASP will not render a submit, but a simple button instead.
Hope that helps! =)
I have a gridview containing membership providers roles.
With Link Button For editing and Link button for deleting.
I want to populate a modal with a text box inside it to save the role name as shown.
I succeeded in populating the modal and binding the grid and all of that, but, how can I bind the txtRoleName in the modal with the role name of the row? Preferably without any postback if possible, or with postback if not.
Here is the code for the grid:
<asp:GridView ID="grdRoles"
CssClass="table table-bordered responsive"
runat="server"
GridLines="None"
CellSpacing="-1"
AutoGenerateColumns="False"
OnPageIndexChanging="grdRoles_PageIndexChanging"
OnRowDataBound="grdRoles_RowDataBound"
ShowFooter="True" ShowHeaderWhenEmpty="True" EmptyDataText="Empty !">
<Columns>
<asp:TemplateField HeaderText="#">
<ItemTemplate>
<asp:Label ID="lblRank" runat="server" Text='<%# Container.DataItem %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Roles">
<ItemTemplate>
<asp:Label ID="lblRoleName" runat="server" Text='<%# Container.DataItem %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnEdit" data-toggle="modal" href="#EditModal" runat="server" CssClass="btn icon-edit" />
<asp:LinkButton ID="btnRemove" runat="server" CssClass="btn btn-danger remove" Text="<i class=icon-remove></i>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And this is the code for the modal:
<div id="EditModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="Edit"
aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="helpModalLabel"><i class="icon-external-link"></i> Edit Role</h3>
</div>
<div class="modal-body">
<div class="control-group">
<div class="controls">
<div class="input-prepend">
<span class="add-on">Role Name</span>
<asp:TextBox ID="txtRoleName" Text='<%# Bind("RoleId") %>' runat="server"></asp:TextBox>
</div>
</div>
<div class="form-actions">
<asp:Button ID="btnSave" type="submit" class="btn btn-primary" runat="server" Text="Save" />
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
I am using data property to send data to the modal:
<a id="edit" href="#dlgName" data-toggle="modal" role="button"
data-id="<%# DataBinder.Eval (Container.DataItem, "Id") %>"
data-IsPrimary ="<%# DataBinder.Eval(Container.DataItem, "IsPrimary") %>" >Edit</a>
And, retrieve the data using jQuery:
var Id = $('#edit').data('Id');
var isprimary = $('#edit').data('IsPrimary');