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.
Related
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 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" />
EDIT: I have found my issue. I was using this line of code in the page load of my master page :
ScriptManager.RegisterStartupScript(Page, Me.GetType(), "fadeAllPartners", "fadeAll();", True)
I have this trouble in my master page contact form and in all the sub page form too.
In fact, I cannot get one update panel work..
I also tried to remove the triggers tag but without success.
All my page work with a master page which include the script manager here :
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" />
<div id="pageWrapper">
<asp:ContentPlaceHolder ID="ContentPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
Here is one example of a form which refresh the whole page :
<asp:UpdatePanel runat="server" ID="UpdatePanelContacter" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="submitEmail" EventName="Click" />
</Triggers>
<ContentTemplate>
<div runat="server" id="BodyFooterForm" class="formSubmitEmail">
<h4>
<%=Resources.LangueRessources.FooterContactezNous%>
</h4>
<div class="centerFormContact">
<span id="lblCompany" runat="server" >
<%=Resources.LangueRessources.FooterFormContactCie%>
<b id="imgCompany" runat="server" ></b>
</span>
<input runat="server" type="text" id="txtCompany" >
<span runat="server" id="lblNom" >
<%=Resources.LangueRessources.FooterFormContactNom%>
<b id="imgNom" runat="server" ></b>
</span>
<input runat="server" type="text" name="txtNom" id="txtNom">
<span runat="server" id="lblEmail" >
<%=Resources.LangueRessources.FooterFormContactEmail%>
<b id="imgEmail" runat="server" ></b>
</span>
<input runat="server" type="text" name="txtEmail" id="txtEmail" >
<span runat="server" id="lblPhone" >
<%=Resources.LangueRessources.FooterFormContactPhone%>
<b id="imgPhone" runat="server" ></b>
</span>
<input runat="server" type="text" name="txtPhone" id="txtPhone" data-mask="(999) 999-9999" >
<span runat="server" id="lblTextarea" >
<%=Resources.langueRessources.FooterFormContactComments%>
<b id="imgTextArea" runat="server" ></b>
</span>
<textarea runat="server" id="txtTextarea" ></textarea>
<span id="lblEnvoyer" runat="server" >
<b id="imgEnvoyer" runat="server" ></b>
</span>
<asp:Button runat="server" ID="submitEmail" class="submit" OnClientClick="return ValidateContactForm()" OnClick="submitEmail_CLick" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<div class="clear">
</div>
Thanks !
I have found my issue. I was using this line of code in the page load of my master page :
ScriptManager.RegisterStartupScript(Page, Me.GetType(), "fadeAllPartners", "fadeAll();", True)
I noticed a problem with my buttons within an ASP page within the Twitter Bootstrap. It seems the only class that appears correctly is the "btn" class. If I would like to use "btn btn-primary" a grey gradient appears over my blue button. When I hover over the button it half of it turns blue. I've tried it with the other button styles and I get the same result.
I'm hoping the code below is correct:
<asp:button type="button" id="btnSearch" runat="server" CssClass="btn btn-primary" Text="Search"></asp:button>
Full HTML
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="header.aspx.vb" Inherits="Backend.header" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="css/bootstrap-responsive.css" />
<link rel="stylesheet" href="css/custom.css" />
</head>
<body>
<form id="masterSearch" runat="server">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">Company Name</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li><a href="cart.aspx">
<asp:Label ID="Label1" runat="server" Text="Cart"> </asp:Label></a></li>
<li class="dropdown">
History <b class="caret"></b>
<ul class="dropdown-menu">
<li>New Order</li>
<li>Order History</li>
</ul>
</li>
<li>Invoices</li>
<li class="dropdown">
Returns <b class="caret"></b>
<ul class="dropdown-menu">
<li>Return Previous Order</li>
<li>Return Policy</li>
</ul>
</li>
<li>Rewards Balance</li>
<li>Help</li>
<li>Log Out</li>
</ul>
</div>
</div>
</div>
</div>
<div id="wrap">
<div class="row-fluid">
<div class="container">
<div class="span12">
<asp:Label ID="Label1" class="pull-right" runat="server" Text="Label"></asp:Label>
</div>
</div> <!--/container-->
</div> <!--/row-->
<hr />
<div class="container">
<div class="row-fluid">
<div class="span2">Left Column</div><!--/left sidebar-->
<div class="span8">
<h5 class="pagination-centered">Search By...</h5>
<div class="span12">
<input type="text" id="txtSearch1" placeholder="NDC#, Item#, Item Name..." runat="server" />
<asp:button type="button" id="btnSearch" runat="server" CssClass="btn btn-primary" Text="Search"></asp:button>
</div> <!--/search-->
<div class="searchResults">
<table ID="tblSearchResults" class="table table-bordered">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="Generic" DataField="ItemDesc" />
<asp:BoundField HeaderText="Brand" DataField="BrandName" />
<asp:BoundField HeaderText="Item Number" DataField="ItemNumber" />
<asp:BoundField HeaderText="NDC" DataField="NDC" />
<asp:BoundField HeaderText="Class" DataField="ControlLevel" />
<asp:BoundField HeaderText="Price" DataField="Price" />
<asp:TemplateField HeaderText="Qty">
<ItemTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</table>
</div>
</div><!--/main content -->
<div class="span2">Right Column</div><!--/right sidebar-->
</div><!--/row-->
</div> <!--/container -->
<asp:button type="button" id="btnAdd" class=" btn btn-danger" runat="server" Text="Add to Cart"></asp:button>
<asp:Button ID="btnCheckOut" runat="server" Text="Check Out" />
</form>
</body>
</html>
I don't necessarily remember 100% but after thinking about this a bit more, I think I ran into the same exact thing as you. In looking at some of my old code, I worked around this by using the Link Button instead of the Button control.
<asp:LinkButton CssClass="btn btn-small" runat="server" ID="m_ReportButton" OnClick="OnReportClick" Text="Report" />
<asp:LinkButton CssClass="btn btn-small" runat="server" ID="m_DeleteButton" OnClick="OnDeleteClick" Text="Delete" />
<asp:LinkButton CssClass="btn btn-small" runat="server" ID="m_EditButton" OnClick="OnEditClick" Text="Edit" />
<asp:LinkButton CssClass="btn btn-small" runat="server" ID="m_QuoteButton" OnClick="OnQuoteClick" Text="Quote" />
<asp:LinkButton CssClass="btn btn-small" runat="server" ID="m_ReplyButton" OnClick="OnReplyClick" Text="Reply" />
Thinking back I am almost certain I made this change simply to apply more than just the btn bootstrap class.
I have an ASP.NET 3.5 form with several fields and a sub form inside a ModalPopup. The problem I'm having is with a RequiredFieldValidator inside the ModalPopup. For some reason it is preventing post back inside the ModalPopup. Both the validator and the submit buttons have the same ValidationGroup that is unique to them. Here is the markup for the sub form:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="RoomBuilder.ascx.cs" Inherits="Admin_Controls_RoomBuilder" %>
<link href="../../../../style/FlexStyle.css" rel="stylesheet" type="text/css" id="style"
runat="server" visible="false" />
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="form" style="width: 420px; height: 500px; padding: 3px; position: relative;
text-align: center;">
<div style="width: 280px">
<div class="item smalltitle ">
Title:
</div>
<div class="item">
<asp:TextBox ID="txtTitle" runat="server" Width="250px"></asp:TextBox>
</div>
<div class="item smalltitle gapontop">
Description:
</div>
<div class="item">
<asp:TextBox ID="txtDesc" runat="server" Width="250px" Height="40px" TextMode="MultiLine"></asp:TextBox>
</div>
<div class="item gapontop">
<div class="smalltitle floatLeft" style="width: 120px;">
Room Number
</div>
<div class="smalltitle floatLeft" style="width: 120px;">
Phone
</div>
</div>
<div class="item">
<div class="floatLeft" style="width: 120px;">
<asp:TextBox ID="txtRoomNo" runat="server" Width="100px"></asp:TextBox>
</div>
<div class="floatLeft" style="width: 120px;">
<asp:TextBox ID="txtPhone" runat="server" Width="100px"></asp:TextBox>
</div>
</div>
<div class="item smalltitle gapontop ">
Type:
</div>
<div class="item">
<asp:TextBox ID="txtType" runat="server" Width="250px"></asp:TextBox>
</div>
<div class="item smalltitle gapontop ">
Number of Seats:
<asp:RequiredFieldValidator ID="RequiredFieldValidatortxtNoSeats" runat="server" ErrorMessage="*"
ControlToValidate="txtNoSeats" ValidationGroup="roomVal"></asp:RequiredFieldValidator>
</div>
<div class="item">
<asp:TextBox ID="txtNoSeats" runat="server" Width="50px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Not a number"
ControlToValidate="txtNoSeats" ValidationGroup="roomVal" ValidationExpression="[0-9]*"></asp:RegularExpressionValidator>
</div>
</div>
<!-- ************************************ -->
<div class="topBorder" style="width: 100%; height: 35px; position: absolute; bottom: -8px;
right: 2px; text-align: right; padding-top: 11px;">
<asp:Button ID="btnCancel" runat="server" CssClass="button" Text="Cancel" CausesValidation="false"
OnClick="btnCancel_Click" ValidationGroup="roomVal" />
<asp:Button ID="btnSave" runat="server" CssClass="button" Text="Save" OnClick="btnSave_Click" CausesValidation="true" ValidationGroup="roomVal" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
When the validator is removed (or CausesValidation is set to false), the sub form posts. RegularExpressionValidators don't have this problem. I've run FireBug, but I'm not seeing any obvious errors.
Is there something I'm missing?
Oh my god I'm so stupid!! >:(
Found the reason for the problem. There was another copy of the same control nested inside another control. And (of course) having the same ValidationGroup name as my first control all Required Field Validators fail to work!
Argh! Candidate for a Daily WTF!
Sorry to have wasted everybody's time :(
Can you please check if your Button (or some other control) that open the popup and the modaldialog extender are outside the update panel?
I got strange problems with modalpopup too. I would suggest you to try something different, for example a numericupdown control from the ajaxcontroltoolkit, if you already use it. So you don't need any validator for this.
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<div class="item smalltitle gapontop ">
Number of Seats:
</div>
<div class="item">
<asp:TextBox ID="txtNoSeats" runat="server" Width="50px"></asp:TextBox>
<cc1:NumericUpDownExtender ID="txtNoSeatsExt" runat="server"
Enabled="true" Minimum="1" Maximum="100" TargetControlID="txtNoSeats" Width="50" />
</div>