I am using Bootstrap 3 with ASP.NET webforms and I am completely new to Bootstrap. The webform I am working on uses ASP.net validation controls. My web form has a standard layout with two columns and I am using "form-group" class to group my labels and input fields.
Now the problem is that as I am placing the label, input field as well as its validator in the Bootstrap "form-group" class, the message in the text property of the validator is being displayed in the next line after validation. I want that to be displayed right next to the input field. Is there any alternative way I can do this?
<div class="form-group">
<asp:Label runat="server" AssociatedControlID="txtBox">Address <span class="required">*</span></asp:Label>
<asp:TextBox id="txtBox" runat="server" CssClass="form-control"/>
<asp:RequiredFieldValidator ID="rfvLine1" ValidationGroup="<%# ValidationGroup %>" ControlToValidate="txtBox" runat="server" Display="Dynamic" ErrorMessage="Line 1 is required." Text="*"/>
</div>
Easiest way is to create validation in separate column.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style type="text/css">
.required {
color: #e31937;
font-family: Verdana;
margin: 0 5px;
}
.field-validation-error {
color: #e31937;
font-weight: bold;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<br />
<div class="container form-horizontal">
<div class="form-group">
<asp:Label runat="server"
AssociatedControlID="txtBox"
CssClass="col-xs-12 col-sm-4 control-label">
Address
<span class="required">*</span>
</asp:Label>
<div class="col-xs-12 col-sm-4 ">
<asp:TextBox ID="txtBox" runat="server"
CssClass="form-control" />
</div>
<div class="col-xs-12 col-sm-4 form-control-static">
<asp:RequiredFieldValidator ID="rfvLine1"
ControlToValidate="txtBox" runat="server"
Display="Dynamic"
CssClass="field-validation-error"
Text="Line 1 is required." />
</div>
</div>
<div class="form-group">
<div class="col-xs-12 col-sm-offset-4 col-sm-4 ">
<asp:Button runat="server" ID="SubmitButton"
Text="Submit" CssClass="btn btn-primary" />
</div>
</div>
</div>
</form>
</body>
</html>
Do the following: Updated
<div class="container">
<h4 class="form-signin-heading">Info</h4>
<div class="form-group">
<div class="col-xs-7 col-sm-7">
<asp:TextBox runat="server" placeholder="Garage Name" CssClass="form-control username" ID="txtAddress"></asp:TextBox>
</div>
<div class="col-xs-7 col-sm-5">
<span class="help-inline pull-left">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtAddress"
ErrorMessage="Address is a required field."
ForeColor="Red" Display="Dynamic">
</asp:RequiredFieldValidator>
</span>
</div>
</div>
<br />
<br />
<div class="form-group">
<div class="col-xs-7 col-sm-7">
<asp:Button ID="Button1" runat="server" Text="Add" CssClass="btn btn-lg btn-primary btn-block" />
</div>
</div>
</div>
I hope, this is what you expected:
By the way, you didn't put the end tag in the RequiredFieldValidator.
#jQuery for check "require" validation for only submit button#
<script type="text/javascript">
(function () {'use strict';
window.addEventListener('load', function () {
var form = document.getElementById('needs-validation');
form.addEventListener('submit', function (event) {
if (form.checkValidity() === false)
{
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
}, false);
})();
##Submit button HTML##
<asp:Button ID="Button1" runat="server" Text="Submit" class="btn btn-primary" OnClick="Button1_Click" />
##Non Submit button##
<asp:Button ID="btnSearch" runat="server" class="form-control btn-primary " Width="25%" Text="Find" UseSubmitBehavior="false" OnClick="btnSearch_Click" />
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.
I am having a simple page which has two steps:
step 1: create a username and password when I click next button it has to go to step 2: to enter all the information.
When I click the next button, the step 2 page loads and immediately goes back to step 1. I tried putting the update panels around entire step 2 but then it doesnt allow me to click previous button or submit button. I also tried surrounding all my labels and textboxes with update panel leaving the previous and submit button but somehow it did not work too. Please help me out.
Also I have a bootstrap date picker included in this. I dont understand how to get the date entered in that box in code behind.
Here is my code:
Default.aspx
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Template/Main.Master" CodeBehind="Default.aspx.vb" Inherits="Library._Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap1-css">
<link rel="stylesheet" runat="server" media="screen" href="/css/StyleSheet.css" type="text/css" />
<link rel="stylesheet" runat="server" media="screen" href="~/css/StyleSheet3.css" type="text/css" />
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<%--<script type="text/javascript" src="/js/JavaScript.js"></script>--%>
<script type="text/javascript" src="/js/JavaScript1.js"></script>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="container">
<div class="row">
<div class="span12">
<div class="" id="loginModal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h2 class="col-xs-12 col-md-6" id="Heading1"> Welcome! </h2>
</div>
<div class="modal-body">
<div class="well">
<ul class="nav nav-tabs">
<li class="active">User Login</li>
<li>Manager Login</li>
<li>Create Account</li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane active in" id="Userlogin">
<div class="form-horizontal">
<fieldset>
<asp:UpdatePanel ID="uplogin" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="click" />
</Triggers>
<ContentTemplate>
<div class="control-group">
<asp:Label ID="lblUsername" runat="server" CssClass="col-xs-12" Text="UserName"></asp:Label>
<asp:TextBox ID="txtUsername" runat="server" CssClass="form-control"></asp:TextBox>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<div class="control-group">
<asp:Label ID="lblPassword" runat="server" CssClass="col-xs-12" Text="Password"></asp:Label>
<asp:TextBox ID="txtPassword" TextMode="Password" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="control-group">
<div class="controls">
<asp:UpdatePanel ID="upLogin2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:button cssclass="btn btn-success btn-block" ID="btnULogin" runat="server" Text="Login"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</fieldset>
</div>
</div>
<div class="tab-pane fade" id="ManagerLogin">
<div class="form-horizontal">
<fieldset>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="click" />
</Triggers>
<ContentTemplate>
<div class="control-group">
<asp:Label ID="lblMUserName" runat="server" CssClass="col-xs-12" Text="UserName"></asp:Label>
<asp:TextBox ID="txtMUserName" runat="server" CssClass="form-control"></asp:TextBox>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<div class="control-group">
<asp:Label ID="lblMPassword" runat="server" CssClass="col-xs-12" Text="Password"></asp:Label>
<asp:TextBox ID="txtMPassword" TextMode="Password" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="control-group">
<div class="controls">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:button cssclass="btn btn-success" ID="btnMLogin" runat="server" Text="Login"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</fieldset>
</div>
</div>
<div class="tab-pane fade" id="create">
<div class="form-horizontal">
<fieldset>
<div class="container">
<div class="stepwizard col-md-offset-3">
<div class="stepwizard-row setup-panel">
<div class="stepwizard-step">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="nav-item">
<asp:LinkButton ID="lnkbtnstep1" runat="server" CssClass="nav-link active" href="#step-1" data-toggle="tab" aria-controls="step1" role="tab" title="Step 1" Text="Step 1"></asp:LinkButton>
</li>
<li role="presentation" class="nav-item">
<asp:LinkButton ID="lnkbtnstep2" runat="server" CssClass="nav-link inactive" href="#step-2" data-toggle="tab" aria-controls="step2" role="tab" title="Step 2" Text="Step 2"></asp:LinkButton>
</li>
</ul>
</div>
</div>
</div>
<div role="form">
<div class="row setup-content tab-pane active" id="step-2">
<div class="col-xs-6 col-md-offset-3">
<div class="col-md-12">
<h3>Create Username and Password</h3>
<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="prevBtn" />
</Triggers>
<ContentTemplate>
<div class="form-group">
<asp:Label ID="lblCUsername" runat="server" CssClass="col-xs-12" Text="UserName" class="form-control"></asp:Label>
<asp:TextBox ID="txtCUsername" runat="server" CssClass="form-control" required="required" placeholder="Enter Username"></asp:TextBox>
</div>
<div class="form-group">
<asp:Label ID="lblCPassword" runat="server" CssClass="col-xs-12" Text="Password" class="form-control"></asp:Label>
<asp:TextBox ID="txtCPassword" TextMode="Password" runat="server" CssClass="form-control" required="required" placeholder="Enter Password"></asp:TextBox>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<div>
<asp:Button ID="prevBtn" runat="server" CssClass="btn btn-primary prevBtn btn-lg pull-left" Text="Previous" />
<asp:Button ID="btnSubmit" runat="server" CssClass="btn btn-primary btn-lg" Text="submit" />
</div>
</div>
</div>
</div>
</div>
<div class="row setup-content" id="step-1">
<div class="col-xs-6 col-md-offset-3">
<div class="col-md-12">
<h3>Add Information</h3>
<asp:UpdatePanel runat="server" UpdateMode="conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="nextBtn" />
</Triggers>
<ContentTemplate>
<div class="form-group">
<asp:Label ID="lblFirstName" runat="server" CssClass="col-xs-12" AssociatedControlID="txtFirstName" class="form-control" Text="FirstName"></asp:Label>
<asp:TextBox ID="txtFirstName" runat="server" CssClass="form-control" placeholder="Enter First Name"></asp:TextBox>
</div>
<div class="form-group">
<asp:Label ID="lblLastName" runat="server" CssClass="col-xs-12" AssociatedControlID="txtLastName" class="form-control" Text="LastName"></asp:Label>
<asp:TextBox ID="txtLastName" runat="server" CssClass="form-control" placeholder="Enter Last Name"></asp:TextBox>
</div>
<div class="form-group">
<asp:Label ID="lblAddress" runat="server" CssClass="col-xs-12" AssociatedControlID="txtAddress" class="form-control" Text="Address"></asp:Label>
<asp:TextBox ID="txtAddress" runat="server" CssClass="form-control" placeholder="Enter Address"></asp:TextBox>
</div>
<div class="form-group">
<asp:Label ID="lblDOB" runat="server" CssClass="col-xs-12" class="form-control" Text="Date Of Birth" Font-Bold="true"></asp:Label>
<div class="row">
<!-- Include Bootstrap Datepicker -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker.min.css" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker3.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.min.js"></script>
<div class="form-group">
<div class="col-xs-12 date">
<div class="input-group input-append date" id="datePicker">
<input type="text" class="form-control" name="date" />
<span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('#datePicker')
.datepicker({
format: 'mm/dd/yyyy'
})
.on('changeDate', function(e) {
// Revalidate the date field
$('#eventForm').formValidation('revalidateField', 'date');
});
$('#eventForm').formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
name: {
validators: {
notEmpty: {
message: 'The name is required'
}
}
},
date: {
validators: {
notEmpty: {
message: 'The date is required'
},
date: {
format: 'MM/DD/YYYY',
message: 'The date is not a valid'
}
}
}
}
});
});
</script>
</div>
</div>
<div class="form-group">
<asp:Label ID="lblEmail" runat="server" CssClass="col-xs-12" AssociatedControlID="txtEmail" class="form-control" Text="Email"></asp:Label>
<asp:TextBox ID="txtEmail" runat="server" CssClass="form-control" placeholder="Enter Email"></asp:TextBox>
</div>
<div class="form-group">
<asp:Label ID="lblPhoneNumber" runat="server" CssClass="col-xs-12" AssociatedControlID="txtPhoneNumber" class="form-control" Text="Phone Number"></asp:Label>
<asp:TextBox ID="txtPhoneNumber" runat="server" CssClass="form-control" placeholder="Enter Primary Phone Number"></asp:TextBox>
</div>
<div class="form-group">
<asp:Label ID="lblSecondaryNumber" runat="server" CssClass="col-xs-12" AssociatedControlID="txtSecondaryNumber" class="form-control" Text="Secondary Phone Number"></asp:Label>
<asp:TextBox ID="txtSecondaryNumber" runat="server" CssClass="form-control" placeholder="Enter Secondary Phone Number"></asp:TextBox>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<div>
<asp:Button ID="nextBtn" runat="server" CssClass="btn btn-primary nextBtn btn-lg pull-right" Text="Next" />
</div>
</div>
</div>
</div>
</div>
</fieldset>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Default.aspx.vb
Public Class _Default
Inherits Library.Helper
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
txtUsername.Focus()
End If
End Sub
Protected Sub btnULogin_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnULogin.Click
InitiateULogin()
End Sub
Protected Sub btnMLogin_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMLogin.Click
InitiateMLogin()
End Sub
Protected Sub btnSubmit_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
InitiateCreateUserName()
InitiateAdd()
End Sub
Private Sub InitiateULogin()
Try
Dim conn As New Connection(Connection.EConnectionString.Library)
Using conn.Connection
Actions.ULogin(txtUsername.Text.Trim(), txtPassword.Text.Trim(), "User", conn.Connection)
End Using
Catch ex As Exception
Library.Helper.ShowMessage(ex.Message)
End Try
End Sub
Private Sub InitiateMLogin()
Try
Dim conn As New Connection(Connection.EConnectionString.Library)
Using conn.Connection
Actions.MLogin(txtMUserName.Text.Trim(), txtMPassword.Text.Trim(), "Manager", conn.Connection)
End Using
Catch ex As Exception
Library.Helper.ShowMessage(ex.Message)
End Try
End Sub
Private Sub InitiateCreateUserName()
Try
Dim conn As New Connection(Connection.EConnectionString.Library)
Using conn.Connection
Actions.CreateUserId(txtCUsername.Text, txtCPassword.Text, "User", conn.Connection)
End Using
Catch ex As Exception
Library.Helper.ShowMessage(ex.Message)
End Try
End Sub
End Class
I am quite new to ASP.NET so forgive me if I have the functionality wrong.
I am working with Bootstrap and have a button within a tab and UpdatePanel which fires a Modal.
The Modal sits behind the screen and blacks out and I can't quite work out why.
If I take the UpdatePanel out, it works. I need the UpdatePanel because it is in a tab with an action CheckBox which without the UpdatePanel sends the user back to the first tab.
<div class="tab-pane fade" id="neworder">
<asp:UpdatePanel ID="up_New_Order" runat="server">
<ContentTemplate>
<div class="checkbox">
<asp:CheckBox ID="cb_Auto_Fill" runat="server" Text="Auto fill last order" CssClass="checkbox" AutoPostBack="true" OnCheckedChanged="cb_Auto_Fill_CheckedChanged"></asp:CheckBox>
</div>
<div class="col-md-6">
<!-- New Order -->
<asp:panel class="row form-group has-feedback" id="Panel2" runat="server">
<label for="inputName" class="col-lg-4 control-label">Ordered By</label>
<div class="col-lg-8">
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:TextBox CssClass="form-control" ID="tb_Ordered_By" placeholder="Customer name" runat="server"></asp:TextBox>
</div>
</asp:panel>
<asp:panel class="row form-group has-feedback" id="Panel5" runat="server">
<label for="inputSubject" class="col-lg-4 control-label">PO No/Agency</label>
<div class="col-lg-8">
<asp:TextBox CssClass="form-control" ID="tb_Po_Number" placeholder="PO No/Agency Ref" runat="server"></asp:TextBox>
</div>
</asp:panel>
<asp:panel class="row form-group has-feedback" id="Panel13" runat="server">
<label for="inputSubject" class="col-lg-4 control-label">Payment Type</label>
<div class="col-lg-8">
<asp:DropDownList ID="ddl_Payment_Type" runat="server" CssClass="form-control dropdown"></asp:DropDownList>
</div>
</asp:panel>
<asp:panel class="row form-group has-feedback" id="Panel14" runat="server" Visible="false">
<label for="inputSubject" class="col-lg-4 control-label">Upload</label>
<div class="col-lg-8">
<input type="file"
style="visibility:hidden; width: 1px;height:1px"
id='${multipartFilePath}' name='${multipartFilePath}'
onchange="$(this).parent().find('span').html($(this).val().replace('C:\\fakepath\\', ''))" /> <!-- Chrome security returns 'C:\fakepath\' -->
<input class="btn btn-primary" type="button" value="Upload File.." onclick="$(this).parent().find('input[type=file]').click();"/> <!-- on button click fire the file click event -->
<span class="badge badge-important" ></span>
</div>
</asp:panel>
<asp:panel class="row form-group has-feedback" id="Panel11" runat="server">
<label for="inputSubject" class="col-lg-4 control-label">Order Notes</label>
<div class="col-lg-8">
<asp:TextBox id="tb_Order_Notes" cssClass="form-control" TextMode="multiline" Columns="50" Rows="3" runat="server" />
</div>
</asp:panel>
</div>
<div class="col-md-6">
<!-- New Order -->
<asp:panel class="row form-group has-feedback" id="Panel7" runat="server">
<label for="inputName" class="col-lg-4 control-label">Copy Contact</label>
<div class="col-lg-8">
<asp:Label ID="Label2" runat="server"></asp:Label>
<asp:TextBox CssClass="form-control" ID="tb_Copy_Contact" runat="server"></asp:TextBox>
</div>
</asp:panel>
<asp:panel class="row form-group has-feedback" id="Panel8" runat="server">
<label for="inputName" class="col-lg-4 control-label">Copy Supply</label>
<div class="col-lg-8">
<asp:TextBox CssClass="form-control" ID="tb_Copy_Supply" runat="server"></asp:TextBox>
</div>
</asp:panel>
<asp:panel class="row form-group has-feedback" id="Panel9" runat="server">
<label for="inputEmail" class="col-lg-4 control-label">Copy Tel</label>
<div class="col-lg-8">
<asp:TextBox CssClass="form-control" ID="tb_Copy_Tel" runat="server"></asp:TextBox>
</div>
</asp:panel>
<asp:panel class="row form-group has-feedback" id="Panel10" runat="server">
<label for="inputSubject" class="col-lg-4 control-label">Copy Email</label>
<div class="col-lg-8">
<asp:TextBox CssClass="form-control" ID="tb_Copy_Email" runat="server"></asp:TextBox>
</div>
</asp:panel>
<div class="row form-group">
</div>
<div class="row form-group">
<div class="col-lg-12">
<asp:Button Text="Create Order" ID="btn_Create_Order" CssClass="btn btn-primary btn-block" OnClick="btn_Create_Order_Click" runat="server" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
The modal sits just above my closing tag for Content and I call it with:
protected void btn_Create_Order_Click(object sender, EventArgs e)
{
lblModalTitle.Text = "Modal Title";
lblModalBody.Text = "Modal Body.";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal().appendTo('body');", true);
upModal.Update();
//pnlAlertBox.Visible = true;
}
Here is the modal (I am reusing it so I know it does work).
<!-- Bootstrap Modal Dialog -->
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<asp:UpdatePanel ID="upModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><asp:Label ID="lblModalTitle" runat="server" Text=""></asp:Label></h4>
</div>
<div class="modal-body">
<asp:Label ID="lblModalBody" runat="server" Text=""></asp:Label>
</div>
<div class="modal-footer">
<button class="btn btn-info" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
I tried your code in my sample project and the bootstrap modal works correctly. I am using jquery 2.1.3
It could be that the jquery version you are using is causing the problem.
I have a ModalPopUpExtender that contains a button that display a second ModalPopUpExtender . The problem is that when I show the second ModalPopUpExtender it appears behind the first. Is it any way i can set that the second ModalPopUpExtender was shown ahead of the fist one?
<asp:ToolkitScriptManager ID="ToolkitScriptManagerProfesiones" runat="server">
</asp:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanelAgenda" runat="server">
<ContentTemplate>
<DayPilot:DayPilotCalendar ID="DayPilotCalendar1" runat="server" BackColor="#FFFFD5" BorderColor="Black" CssClassPrefix="calendar_default" DayFontFamily="Tahoma" DayFontSize="15pt" DurationBarColor="Blue" EventBackColor="White" EventBorderColor="Black" EventClickHandling="PostBack" EventFontFamily="Tahoma" EventFontSize="8pt" EventHoverColor="Gainsboro" HourBorderColor="#EAD098" HourFontFamily="Tahoma" HourFontSize="16pt" HourHalfBorderColor="#F3E4B1" HourNameBackColor="#ECE9D8" HourNameBorderColor="#ACA899" HourWidth="100" HoverColor="#FFED95" NonBusinessBackColor="#FFF4BC" StartDate="2015-03-25" TimeFormat="Clock24Hours" CellHeight="40" HeaderHeight="40" OnEventClick="DayPilotCalendar1_EventClick" OnTimeRangeSelected="DayPilotCalendar1_TimeRangeSelected" style="top: 0px; left: 0px; width: 375px; height: 501px; margin-right: 221px" Width="600px" TimeRangeSelectedHandling="PostBack" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:ModalPopupExtender ID="modificarTurno_ModalPopupExtender" runat="server" Enabled="True" PopupControlID="PanelModificarTurno" DropShadow="false" BackgroundCssClass="FondoAplicacion" TargetControlID="lb">
</asp:ModalPopupExtender>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" Enabled="True" PopupControlID="panelClientes" DropShadow="false" BackgroundCssClass="FondoAplicacion" TargetControlID="lbClientePop">
</asp:ModalPopupExtender>
<asp:Button ID="Button1" class="btn btn-info" runat="server" Text="Modificar" Visible="false" />
<asp:Panel ID="panelClientes" runat="server" >
<asp:Label ID="lbClientePop" runat="server" Style="display: none " ></asp:Label>
<asp:UpdatePanel ID="UpdatePanelCliente" runat="server">
<ContentTemplate>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" >
<h2> prueba</h2>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="PanelModificarTurno" runat="server" >
<asp:Label ID="Lb" runat="server" Style="display: none"></asp:Label>
<asp:UpdatePanel ID="UpdatePanelModificarTurno" runat="server">
<ContentTemplate>
<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="myModalLabelModificar16">Modificar turno</h4>
</div>
<div class="modal-body">
<div class="form-horizontal">
<fieldset>
<div class="form-group">
<label for="DropDownEstado" class="col-lg-2 control-label">Estado</label>
<div class="col-lg-6">
<asp:DropDownList ID="DropDownEstado" runat="server" CssClass="form-control" DataSourceID="SqlDataSourceEstado" DataTextField="estado" DataValueField="id"></asp:DropDownList>
<asp:SqlDataSource runat="server" ID="SqlDataSourceEstado" ConnectionString='<%$ ConnectionStrings:MiWeb.Properties.Settings.cs %>' SelectCommand="SELECT * FROM [Estado]"></asp:SqlDataSource>
</div>
</div>
<div class="form-group">
<asp:UpdatePanel ID="updatepanelboton" runat="server">
<ContentTemplate>
<label for="txtCliente" class="col-lg-2 control-label">Cliente</label>
<div class="col-lg-4">
<asp:TextBox ID="txtCliente" class="form-control" runat="server"></asp:TextBox>
</div>
<div class="col-lg-2">
<asp:Button runat="server" ID="BtnBuscarCliente" Text="..." OnClick="BtnBuscarCliente_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="form-group">
<label for="DropdownServicios" class="col-lg-2 control-label">Servicio</label>
<div class="col-lg-6">
<asp:DropDownList ID="DropdownServicios" runat="server" CssClass="form-control" DataSourceID="SqlDataSourceServicios" DataTextField="nombre" DataValueField="id" OnSelectedIndexChanged="DropdownServicios_SelectedIndexChanged"></asp:DropDownList>
<asp:SqlDataSource runat="server" ID="SqlDataSourceServicios" ConnectionString='<%$ ConnectionStrings:MiWeb.Properties.Settings.cs %>' SelectCommand="SELECT * FROM [Servicios] WHERE ([activo] = #activo)">
<SelectParameters>
<asp:Parameter DefaultValue="true" Name="activo" Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</div>
<div class="form-group">
<label for="DropDownProfesioanles" class="col-lg-2 control-label">Profesional</label>
<div class="col-lg-6">
<asp:DropDownList ID="DropDownProfesioanles" runat="server" CssClass="form-control" ></asp:DropDownList>
</div>
</div>
<div class="form-group">
<label for="ChkPrimeraVez" class="col-lg-2 control-label">Primera vez? </label>
<div class="col-lg-6">
<asp:CheckBox ID="ChkPrimeraVez" runat="server" />
</div>
</div>
<div class="form-group">
<label for="DropDownHsInicio" class="col-lg-2 control-label">Inicio</label>
<div class="col-lg-4">
<asp:DropDownList ID="DropDownHsInicio" runat="server" CssClass="form-control" DataSourceID="SqlDataSourceHI" DataTextField="hora" DataValueField="id"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceHI" runat="server" ConnectionString='<%$ ConnectionStrings:MiWeb.Properties.Settings.cs %>' SelectCommand="SELECT * FROM [horarios]"></asp:SqlDataSource>
</div>
<label for="DropDownHsFin" class="col-lg-2 control-label">Fin</label>
<div class="col-lg-4">
<asp:DropDownList ID="DropDownListFin" runat="server" CssClass="form-control" DataSourceID="SqlDataSourceFI" DataTextField="hora" DataValueField="id" Enabled="False"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceFi" runat="server" ConnectionString='<%$ ConnectionStrings:MiWeb.Properties.Settings.cs %>' SelectCommand="SELECT * FROM [horarios]"></asp:SqlDataSource>
</div>
</div>
</fieldset>
</div>
</div>
<div class="modal-footer">
<asp:Button ID="BtnEliminarTurno" runat="server" class="btn btn-danger" Text="Eliminar turno" OnClick="BtnEliminarTurno_Click" />
<asp:Button ID="btnCancelarMod" runat="server" class="btn btn-default" Text="Cancelar" OnClick="btnCancelarMod_Click" />
<asp:Button ID="btnConfirmarMod" runat="server" class="btn btn-success" Text="Modificar" OnClick="btnConfirmarMod_Click" />
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
protected void btnConfirmarMod_Click(object sender, EventArgs e)
{
modificarTurno_ModalPopupExtender.Hide();
}
protected void BtnBuscarCliente_Click(object sender, EventArgs e)
{
ModalPopupExtender1.Show();
}
thanks in advance !
ModalPopupExtender "decides" on its own what z-index to use. Generally it will do the right thing.
The only way I know to assure that your second one will appear on top is to Not use a second ModalPopupExtender, but instead to assign the z-index of the second modal popup explicitly. I suggest 99999 for the second popup and 99998 for its blanket. I have seen typical z-index assigned by ModalPopupExtender in ranges of 50000 to 79000 (aprox).
I am not sure how to formulate the title of this issue. My problem is that I have a .ascx control which has control. When I make a page where I have buttons in the content, pressing the button causes Submit button to be fired.... I have absolutely no idea why this happens. Please give me any suggestions or idea how to fix this.
My Control code is :
<%# Control Language="VB" AutoEventWireup="false" CodeFile="TopRightMenuAnonn.ascx.vb" Inherits="Ctrls_TopRightMenuAnonn" %>
<ul class="nav pull-right" id="top-right_menu">
<li style="padding: 5px" class="dropdown">
<a class="dropdown-toggle" href="#" data-toggle="dropdown" style="padding:10px 15px;color: #73767D">Login<strong class="caret"></strong></a>
<div id="loginForm" class="dropdown-menu pull-right" style="padding: 15px;">
<asp:Login runat="server" ID="login1" DestinationPageUrl="~/Home.aspx">
<LayoutTemplate>
<asp:TextBox runat="server" ID="Username" style="margin-bottom:15px;" PlaceHolder="Username" Height="30px"></asp:TextBox>
<asp:TextBox runat="server" ID="Password" style="margin-bottom: 15px;" PlaceHolder="Password" Height="30px" TextMode="Password" />
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="Username" style="color: red" Text="Please enter an username."></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" style="color: red" Text="Please enter a password."></asp:RequiredFieldValidator>
<asp:Label ID="lblError" runat="server" Visible="false" Text=""></asp:Label>
<asp:Button ID="Login" runat="server" CommandName="Login" CssClass="btn btn-primary" style="clear: left; width: 100%; height: 32px; font-size: 13px;" Text="Sign In"></asp:Button>
Forgot password?<br />
<!--Fancybox for pass-->
<div style="display:none">
<div id="getpass" style="width: 100%;height:100%">
<span>Please enter your username to retrieve your password.</span>
<br />
<asp:TextBox runat="server" ID="txtForgotPass" PlaceHolder="Username" Height="30px" Width="100%" style="margin-top: 20px;margin-bottom:20px;"></asp:TextBox>
<asp:Button runat="server" ID="btnForgotPass" CssClass="btn btn-primary" style="clear:left;float: right;padding:10px" Text="Send My Password" />
</div>
</div>
<!--End of fancybox for pass-->
Forgot username?
<!-- Fancybox for user -->
<div style="display:none">
<div id="getuser" style="width: 100%;height: 100%">
<span>Please enter your e-mail to retrieve your username.</span>
<br />
<asp:TextBox runat="server" ID="txtForgotUser" PlaceHolder="example#materialconnexion.com" Height="30px" Width="100%" style="margin-top: 20px; margin-bottom: 20px;"></asp:TextBox>
<asp:Button runat="server" ID="btnForgotUser" CssClass="btn btn-primary" style="clear:left;float: right;padding: 10px" Text="Send My Username" />
</div>
</div>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="login1" />
<!-- End of fancybox for user-->
</LayoutTemplate>
</asp:Login>
</div>
</li>
<li style="padding: 15px;border-left: 1px solid #999"><a style="padding: 0px !important;color: #73767D" href="../regtest.aspx">Register</a></li>
<li style="padding: 15px;border-left: 1px solid #999"><a style="padding: 0px !important;color: #73767D" href="../Pricing.aspx">Buy Credits</a></li>
</ul>
My control back-end code is(this is where shit happens and I cant figure out a way to make it work properly) :
Option Strict On
Partial Class Ctrls_TopRightMenuAnonn
Inherits System.Web.UI.UserControl
Protected Sub login1_LoggingIn(sender As Object, e As LoginCancelEventArgs) Handles login1.LoggingIn
Dim m As New MemberData(New MatconnDB(), login1.UserName)
If m.IsNew() Then
e.Cancel = True 'not in database
Return
End If
If m.ExpirationDate < Now() Then
e.Cancel = True
Return
End If
If m.Active = False Then
Return
End If
If m.unameEmail = False Then
Return
End If
If (MemberData.GetPassword(login1.UserName.ToString()) = MemberData.Encrypt(login1.Password.ToString())) Then
Session("User") = login1.UserName.ToString()
Response.Redirect("~/Home.aspx")
ElseIf MemberData.GetPassword(login1.UserName.ToString()) = login1.Password.ToString() Then
Session("User") = login1.UserName.ToString()
Response.Redirect("~/Home.aspx")
' Else
'I should put proper error messages here !!!!!!
End If
End Sub
End Class
My Master page file is :
<%# Master Language="VB" CodeFile="TopMenu.master.vb" Inherits="MasterPageLogged" AutoEventWireup="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>ssds</title>
</head>
<body>
<form id="form1" runat="server">
<div id="wrap">
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container" id="cont_left-menu">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#left-menu">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="HomePage.aspx">
<img style="margin-top: -5px;" src="../images/mc-logo.jpg" />
</a>
</div>
<div class="collapse navbar-collapse" id="left-menu">
<ul class="nav navbar-nav">
<li>
Services
</li>
<li>
Tool
</li>
<li>
Work
</li>
<li>
Matter
</li>
<li>
About
</li>
<li>
Contact
</li>
</ul>
<asp:ContentPlaceHolder runat="server" ID="ContentTopMenuRight">
</asp:ContentPlaceHolder>
</div>
</div>
</nav>
<asp:ContentPlaceHolder runat="server" ID="ContentPlaceHolder1">
</asp:ContentPlaceHolder>
</div>
</form>
<link type="text/css" rel="stylesheet" href="../css/bootstrap.css"/>
<link type="text/css" rel="stylesheet" href="../css/bootstrap-theme.css"/>
<link type="text/css" rel="stylesheet" href="../css/Styles.css" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="../js/jquery.fancybox.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="../css/jquery.fancybox.css" type="text/css" media="screen" />
</body>
</html>
And my Simple test page is :
<%# Page Language="VB" AutoEventWireup="false" MasterPageFile="~/Masters/TopMenu.master" CodeFile="regtest.aspx.vb" Inherits="regtest" %>
<%# Register Src="~/Ctrls/TopRightMenuAnonn.ascx" TagName="TopRightMenuLogged" TagPrefix="tma" %>
<%# MasterType VirtualPath="~/Masters/TopMenu.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentTopMenuRight" runat="server">
<tma:TopRightMenuLogged ID="TopRightMenuLogged1" runat="server" />
</asp:Content>
<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<div class="container">
<div class="col-md-6">
<asp:TextBox runat="server" ID="txtName" PlaceHolder="Name" class="txtedit"></asp:TextBox>
<asp:TextBox runat="server" ID="txtSurname" PlaceHolder="Surname" class="txtedit"></asp:TextBox>
<asp:TextBox runat="server" ID="txtMail" PlaceHolder="Email" class="txtedit"></asp:TextBox>
<asp:TextBox runat="server" ID="txtCompany" PlaceHolder="Company" class="txtedit"></asp:TextBox>
<asp:TextBox runat="server" ID="txtPass" PlaceHolder="Password" class="txtedit"></asp:TextBox>
<asp:TextBox runat="server" ID="txtPassV" PlaceHolder="Confirm Password" class="txtedit" AutoPostBack="True"></asp:TextBox>
<br />
<br />
<asp:CheckBox runat="server" ID="chkbox" Text=" Term and Conditions" style="margin-top: 10px" />
<br />
<br />
<br />
<br />
<asp:Button runat="server" ID="btnReg" Text="blqblq" />
<asp:Label runat="server" ID="lblText" Text=""></asp:Label>
<asp:Label runat="server" ID="lblCaption" Text=""></asp:Label>
</div>
</div>
</asp:Content>
Please advise..
Thanks in advance !
The MSDN docs page for the Button class states in a few places:
By default, all button controls submit the page when clicked.
It is unclear from your question which <asp:Button> control is causing the unwanted PostBack:
the one in your sample page (btnReg), or
one of the ones in your UserControl (Login, btnForgotPass, btnForgotUser)
However, if you don't want them to submit the page / cause a PostBack, then you need to
prevent that using client-side validation / etc, or
use a different control than <asp:Button> that does what you want it to.