I am trying to trigger an SelectedIndexChanged from the ddlMake dropdownlist but the event is not firing, if I shift the ddlMake outside of my CreateUserWizard, it will work. Am I doing anything wrong:
<asp:CreateUserWizard runat="server" ID="RegisterUser" ViewStateMode="Disabled" OnCreatingUser="RegisterUser_CreatingUser" OnCreatedUser="RegisterUser_CreatedUser" >
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="wizardStepPlaceholder" />
<asp:PlaceHolder runat="server" ID="navigationPlaceholder" />
</LayoutTemplate>
<WizardSteps>
<asp:CreateUserWizardStep runat="server" ID="CreateUserWizardStep1">
<ContentTemplate>
<p class="message-info">
Passwords are required to be a minimum of <%: Membership.MinRequiredPasswordLength %> characters in length.
</p>
<p class="validation-summary-errors">
<asp:Literal runat="server" ID="ErrorMessage" />
</p>
<div class="row-fluid MT35">
<div class="span3">User ID:</div>
<div class="span8">
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="UserName"
CssClass="field-validation-error"
ErrorMessage="The user name field is required." Display="Dynamic" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" Text="Username length must be between 5 to 12 characters without spacing."
ControlToValidate="UserName" SetFocusOnError="true"
ValidationExpression="^[a-zA-Z0-9'#&#_]{5,12}$" Display="Dynamic" />
</div>
<div class="row-fluid ">
<div class="span3">Password:</div>
<div class="span8">
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Password"
CssClass="field-validation-error" ErrorMessage="The password field is required." />
</div>
<div class="row-fluid ">
<div class="span3">Confirm Password:</div>
<div class="span8">
<asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ConfirmPassword"
CssClass="field-validation-error" Display="Dynamic" ErrorMessage="The confirm password field is required." />
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword"
CssClass="field-validation-error" Display="Dynamic" ErrorMessage="The password and confirmation password do not match." />
</div>
</div>
<div class="row-fluid MT35">
<div class="span3">Your Car:</div>
<div class="span8 YourCarInformation">
<asp:DropDownList ID="ddlCarMake" OnSelectedIndexChanged="ddlMake_SelectedIndexChanged" AutoPostBack="True" runat="server" CssClass="span12"></asp:DropDownList>
<asp:DropDownList ID="ddlCarModel" runat="server" CssClass="span12"></asp:DropDownList>
<asp:TextBox ID="txtRegistration" CssClass="pull-left" runat="server" placeholder="registration date dd/mm/yyyy"></asp:TextBox>
</div>
</div>
</div>
<div class="row-fluid">
<div class="span3">Recieve Newsletter:</div>
<div class="span8 RadioBtn">
<label class="radio">
<asp:RadioButtonList ID="rbNewsLetter" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="Yes" Value="true" Selected="True" />
<asp:ListItem Text="No" Value="false" />
</asp:RadioButtonList>
</label>
</div>
</div>
</div>
</div>
</ContentTemplate>
<CustomNavigationTemplate />
</asp:CreateUserWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
DropDownList ddlCarMake =
(DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlCarMake");
DropDownList ddlCarModel =
(DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlCarModel");
ddlCarMake.DataSource = ds.Tables[0];
ddlCarMake.DataTextField = "CarMake";
ddlCarMake.DataValueField = "CarMake";
ddlCarMake.DataBind();
ddlCarMake.Items.Insert(0, new ListItem("Any", ""));
ddlCarMake.Items.Insert(ds.Tables[0].Rows.Count + 1, new ListItem("Others", "Others"));
ddlCarModel.Items.Insert(0, new ListItem("Any", ""));
}
}
protected void ddlMake_SelectedIndexChanged(object sender, EventArgs e)
{
VehicleBLL vehicleBll = new VehicleBLL();
DropDownList ddlCarMake = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlCarMake");
DropDownList ddlCarModel = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlCarModel");
DataSet ds = null;
if (ddlCarMake.SelectedIndex != 0)
{
ds = vehicleBll.GetCarModel(ddlCarMake.SelectedValue);
ddlCarModel.DataSource = ds.Tables[0];
ddlCarModel.DataTextField = "CarModel";
ddlCarModel.DataValueField = "CarModel";
ddlCarModel.DataBind();
ddlCarModel.Items.Insert(0, new ListItem("Any", ""));
}
}
Ok, found the answer after half a day went by, remove the ViewStateMode="Disabled" in the CreateUserWizard control and everything works fine.
i think you have to do this
first put the dropdownlist in update panel
then put the autopostback in dropdownlist property to true
that's will solve the problem
Related
I would like to prevent chrome browser from auto filling the username Textbox in the account login.aspx page that I have created.
I have tried setting the Textbox's AutoCompleteMode property to "None" or to "Disabled" but still nothing.
My front end code for login:
<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false" onloggedin="LoginUser_LoggedIn">
<LayoutTemplate>
<span class="failureNotification">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
</span>
<asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification"
ValidationGroup="LoginUserValidationGroup"/>
<div class="accountInfo">
<fieldset class="login">
<legend><asp:Literal ID="Literal3" runat="server" Text="<%$ Resources:chienvh.language, AccountInformation%>" /></legend>
<p>
<%--<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>--%>
<asp:TextBox ID="UserName" runat="server" CssClass="textEntry" AutoPostBack="true" Placeholder="<%$ Resources:chienvh.language, Username%>" OnTextChanged="UserName_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" CssClass="failureNotification"
ErrorMessage="User Name is required." ToolTip="User Name is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<%--<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>--%>
<asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password" Placeholder="<%$ Resources:chienvh.language, Password%>"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Password is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<asp:DropDownList runat="server" ID="DDLSite" DataSourceID="DSSite" DataValueField="SiteID" DataTextField="Site"></asp:DropDownList>
<asp:SqlDataSource runat="server" ID="DSSite" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
SelectCommand="Select 'Επίλέξτε Site...' [Site], 0 SiteID
union
Select [Site], [SiteID]
from Site
order by [Site]"></asp:SqlDataSource>
</p>
<p>
<asp:CheckBox ID="RememberMe" runat="server"/>
<asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" CssClass="inline">Keep me logged in</asp:Label>
</p>
</fieldset>
<p class="submitButton">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="LoginUserValidationGroup"/>
</p>
</div>
</LayoutTemplate>
</asp:Login>
And the back end:
protected void LoginUser_LoggedIn(object sender, EventArgs e)
{
string error = "";
string User_Name = LoginUser.UserName.ToString();
if (Common.Is_Inactive_User(User_Name, ref error) || error != "")
FormsAuthentication.SignOut();
Roles.DeleteCookie();
Session.Clear();
}
This is my stored procedure :
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[Insert_BranchRegistration]
#branchname varchar(100),
#address nvarchar(200),
#phone bigint,
#email varchar(200),
#bloodgroup int,
#nobags int
as
INSERT INTO [dbo].[BranchRegistration]
([branchname]
,[address]
,[phone]
,[email]
,[bloodgroup]
,[nobags])
VALUES
(#branchname
,#address
,#phone
,#email
,#bloodgroup
,#nobags)
GO
ALTER procedure [dbo].[SP_BGTable] as SELECT [bgid] ,[name] FROM [dbo].[BGTable]
This is my asp.net html code.
<%# Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="BranchRegi.aspx.cs" Inherits="BloodBank.BranchRegi" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="pagecontent">
<div class="addform">
<asp:Button ID="BtnAdd" runat="server" CssClass="button" Text="Add" />
<br />
<asp:Label ID="ErrorMessage" ForeColor="Red" class="label_inv" runat="server" ></asp:Label>
<br />
</div>
<div class="form">
<div class="border-line">
<div>
<span class="width"> <asp:Label ID="lblBranchName" class="label_inv" runat="server" Text="Branch Name"></asp:Label></span>
<span class="leftmargin">
<asp:TextBox ID="txtBranchName" class="textbox_body" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvBranchName" runat="server" ForeColor="Red" ErrorMessage="Please enter branch name." ControlToValidate="txtBranchName"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rxvBranchName" runat="server"
ControlToValidate="txtBranchName" ErrorMessage="Only alphabets are allowed"
ForeColor="Red" ValidationExpression="[a-zA-Z]+"> </asp:RegularExpressionValidator></span>
</div>
<br />
<div>
<span class="width"> <asp:Label ID="lblAddress" class="label_inv" runat="server" Text="Address"></asp:Label></span>
<span style="margin-left:95px"> <asp:TextBox ID="txtAddress" Style="height: 70px" class="textbox_body" runat="server" TextMode="multiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvAddress" ForeColor="Red" runat="server" ErrorMessage="Please enter Address." ControlToValidate="txtAddress"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rxvAddress" runat="server"
ControlToValidate="txtAddress" ErrorMessage="Only alphabets are allowed"
ForeColor="Red" ValidationExpression="[a-zA-Z]+" > </asp:RegularExpressionValidator></span>
</div>
<br />
<div>
<span class="width"> <asp:Label ID="lblPhoneNumber" class="label_inv" runat="server" Text="Phone Number"></asp:Label></span>
<span class="leftmargin" style="margin-left:50px"> <asp:TextBox ID="txtPhonenumber" class="textbox_body" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvPhonenumber" ForeColor="Red" runat="server" ErrorMessage="Please enter phone number." ControlToValidate="txtPhonenumber"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtPhonenumber" ErrorMessage="Please enter valid mobile number"
ValidationExpression="[0-9]{10}"></asp:RegularExpressionValidator></span>
</div>
<br />
<div>
<span class="width"> <asp:Label ID="lblEmailID" class="label_inv" runat="server" Text="Email ID"></asp:Label></span>
<span class="leftmargin" style="margin-left:85px" ><asp:TextBox ID="txtEmailID" class="textbox_body" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmailID" ForeColor="Red" runat="server" ErrorMessage="Please enter email." ControlToValidate="txtEmailID"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2"
runat="server" ErrorMessage="Please Enter Valid Email ID"
ValidationGroup="vgSubmit" ControlToValidate="txtEmailID"
CssClass="requiredFieldValidateStyle"
ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator></span>
</div>
<br />
<div>
<span class="width"><asp:Label ID="lblGroup" class="label_inv" runat="server" Text="Blood Group"></asp:Label></span>
<span class="leftmargin">
<asp:DropDownList ID="ddlBlood" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvBloodGroup" ForeColor="Red" runat="server" ErrorMessage="Please enter valid group name." ControlToValidate="ddlBlood"></asp:RequiredFieldValidator>
</span>
</div>
<br />
<div>
<span class="width"> <asp:Label ID="lblNoBags" class="label_inv" runat="server" Text="No. of Bags"></asp:Label></span>
<span class="leftmargin"><asp:TextBox ID="txtNoBags" Style="margin-left: 5px" class="textbox_body" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvNoBags" ForeColor="Red" runat="server" ErrorMessage="Please enter branch name." ControlToValidate="txtNoBags"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator id="RegularExpressionValidator4"
ControlToValidate="txtNoBags"
ValidationExpression="\d+"
Display="Static"
EnableClientScript="true"
ErrorMessage="Please enter numbers only"
runat="server"/></span>
</div>
<br />
<div>
<span class="width" style="margin-left:200px" ><asp:Button ID="invSubmit" runat="server" Text="Submit" OnClick="invSubmit_Click" /></span>
<span style="margin-left:50px" > <asp:Button ID="invReset" runat="server" Text="Reset" /></span>
</div>
</div>
</div>
</div>
<link href="Content/site1.css" rel="stylesheet" />
<style>
.leftmargin
{
margin-left:60px;
}
.width
{
width:200px;
}
</style>
</asp:Content>
and server side C# code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using BloodBank.Controllers;
using BloodBank.Models;
namespace BloodBank
{
public partial class BranchRegi : System.Web.UI.Page
{
#region VARIABLES
DataSet ds = null;
BranchRegistration objBranch;
Operation objOperation;
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
filldrop();
ddlBlood.SelectedIndex = 0;
}
}
public void filldrop()
{
ds = SqlHelper.ExecuteDataset(Common.GetConnectionString(), CommandType.StoredProcedure, CommanName.StoredProcedures.Select_Group);
ddlBlood.DataSource = ds;
ddlBlood.DataTextField = "name";
ddlBlood.DataValueField = "bgid";
ddlBlood.DataBind();
ddlBlood.Items.Insert(0, new ListItem("Select", "0"));
}
protected void invSubmit_Click(object sender, EventArgs e)
{
objBranch = new BranchRegistration();
objOperation = new Operation();
try
{
objBranch.branchname = txtBranchName.Text.Trim();
objBranch.address = txtAddress.Text.Trim();
objBranch.phone = Int64.Parse(txtPhonenumber.Text.Trim());
objBranch.email = txtEmailID.Text.Trim();
//Response.Write(ddlBlood.SelectedValue.ToString());
objBranch.bloodgroup = int.Parse(ddlBlood.SelectedItem.Value);
objBranch.nobags = int.Parse(txtNoBags.Text.Trim());
objOperation.RegisterBranch(objBranch);
ErrorMessage.Text = CommanName.Messages.registerSuccess;
}
catch (Exception)
{
ErrorMessage.Text = CommanName.Messages.registerUnsuccess;
}
}
}
}
and
int iResult = SqlHelper.ExecuteNonQuery(Common.GetConnectionString(), CommandType.StoredProcedure,CommanName.StoredProcedures.Select_Group, new SqlParameter("#branchname", objBranch.branchname), new SqlParameter("#address", objBranch.address), new SqlParameter("#phone", objBranch.phone), new SqlParameter("#email", objBranch.email), new SqlParameter("#bloodgroup", objBranch.bloodgroup), new SqlParameter("#nobags", objBranch.nobags));
The exception is:
Procedure SP_BGTable has no parameters and arguments were supplied.
ALTER procedure [dbo].[SP_BGTable] as SELECT [bgid] ,[name] FROM [dbo].[BGTable]
This is store procedure SP_BGTable. and there is no parameters! But you try to pass parameter in code.
I think you calling the wrong procedure. Change it to Insert_BranchRegistration
I am stuck on passing values from a form on one page to (confirm.aspx) another page. Would someone help me out with this? I am not looking for some one to code my program because I have done much of the work already. Here is what I have, Default.aspx as three values that I need to pass to Confirm.aspx. This is what I have for the Default.aspx.
<form id="form1" runat="server">
<h1>Price quotation</h1>
<label>Sales price</label>
<asp:TextBox ID="txtSalesPrice" runat="server" CssClass="entry">100</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtSalesPrice" Display="Dynamic" ErrorMessage="RequiredFieldValidator" CssClass="validator">Required</asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtSalesPrice" Display="Dynamic" MaximumValue="1000" MinimumValue="10" Type="Double" CssClass="validator">Must be from 10 to 1000</asp:RangeValidator><br /><br />
<label>Discount percent</label>
<asp:TextBox ID="txtDiscountPercent" runat="server" CssClass="entry">20</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtDiscountPercent" Display="Dynamic" ErrorMessage="RequiredFieldValidator" CssClass="validator">Required</asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="txtDiscountPercent" Display="Dynamic" MaximumValue="50" MinimumValue="10" Type="Double" CssClass="validator">Must be from 10 to 50</asp:RangeValidator><br />
<label>Discount amount</label>
<asp:Label ID="lblDiscountAmount" runat="server" CssClass="result" ></asp:Label><br /><br />
<label>Total price</label>
<asp:Label ID="lblTotalPrice" runat="server" CssClass="result" ></asp:Label><br /><br />
<asp:Button ID="btnCalculate" runat="server" Text="Calculate" OnClick="btnCalculate_Click" CssClass="button" />
<asp:Button ID="ConfirmButton" runat="server" CssClass="button" Text="Confirm" PostBackUrl="~/Confirm.aspx" OnClick="ConfirmButton_Click" />
<p><asp:Label ID="lblMessage" runat="server" EnableViewState="false" /></p>
</form>
Code Behind the Default.aspx
protected void ConfirmButton_Click(object sender, EventArgs e)
{
Session["Sales"] = txtSalesPrice.Text;
Response.Redirect("Confirm.aspx");
Session["Amt"] = lblDiscountAmount.Text;
Response.Redirect("Confirm.aspx");
Session["Total"] = lblTotalPrice.Text;
Response.Redirect("Confirm.aspx");
}
Confirm.aspx
<form id="form1" runat="server">
<h1>Quotation confirmation</h1>
<label>Sales price</label><asp:Label ID="lblSalesPrice" runat="server" CssClass="result"></asp:Label><%=Session["Sales"] %><br /><br />
<label>Discount amount</label><asp:Label ID="lblDiscountAmount" runat="server" CssClass="result"><%=Session["Amt"] %></asp:Label><br /><br />
<label>Total price</label><asp:Label ID="lblTotalPrice" runat="server" CssClass="result"><%=Session["Price"] %></asp:Label><br />
<h2>Send confirmation to</h2>
<label>Name</label>
<asp:TextBox ID="txtName" runat="server" CssClass="entry"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName" Display="Dynamic" ErrorMessage="RequiredFieldValidator" CssClass="validator">Required</asp:RequiredFieldValidator><br />
<label>Email address</label>
<asp:TextBox ID="txtEmail" runat="server" CssClass="entry"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="RequiredFieldValidator" CssClass="validator">Required</asp:RequiredFieldValidator><br />
<asp:Button ID="btnSubmit" runat="server" Text="Send Quotation" CssClass="button" OnClick="btnSubmit_Click" />
<asp:Button ID="btnReturn" runat="server" Text="Return" PostBackUrl="~/Default.aspx" CausesValidation="false" CssClass="button" OnClick="btnReturn_Click" />
<p><asp:Label ID="lblMessage" runat="server" ViewStateMode="Enabled" /></p>
</form>
If someone would take the time out and review what I have here. I would appreciate. There is nothing pertinent on the code behind on the Confirm.aspx.cs.
Code behind default.aspx
protected void ConfirmButton_Click(object sender, EventArgs e)
{
Session["Sales"] = txtSalesPrice.Text;
Session["Amt"] = lblDiscountAmount.Text;
Session["Total"] = lblTotalPrice.Text;
Response.Redirect("Confirm.aspx");
}
And you get value in another page like this
In .cs
txtSales.text = Session["Sales"];
In .aspx
<asp:TextBox ID="txtSales" runat="server" Text='<%# Session["Sales"] %>' >
Been using PHP for a long time but now am making a site with ASP.NET. I am attempting to have a basic user registration form but whenever I submit the form, all the data shows to be empty! Also, the tagsinput method doesnt seem to be working.
Here is a basic form, it is in a contentplaceholder. The entire body in the master page is surrounded in a <form runat="server">
<script type="text/javascript">
$(document).ready(function () {
//$("[id$=pick_user_type]").hide();
$("[id$=UserTypeList]").click(function (e) { //second step of registration
$('[id$=UserTypeList] input:checked').each(function () {
//artist
if ((this.value).toLowerCase().indexOf("artist") >= 0) {
$('#whatinstruments').show();
$('#instrumentsplayedtags').prop('disabled', false);
}
//producer
if ((this.value).toLowerCase().indexOf("producer") >= 0) {
$('#whatrecordingplatforms').show();
$('#recordingplatformstags').prop('disabled', false);
}
});
$('[id$=UserTypeList] input:not(:checked)').each(function () { //unchecked
//artist
if ((this.value).toLowerCase().indexOf("artist") >= 0) {
$('#whatinstruments').hide();
$('#instrumentsplayedtags').prop('disabled', true);
}
//producer
if ((this.value).toLowerCase().indexOf("producer") >= 0) {
$('#whatrecordingplatforms').hide();
$('#recordingplatformstags').prop('disabled', true);
}
});
});
$('#artistslikedtags').tagsInput({ //tags for listener
width: 'auto'
});
$('#instrumentsplayedtags').tagsInput({ //tags for artist
width: 'auto'
});
$('#recordingplatformstags').tagsInput({ //tags for producer
width: 'auto'
});
});
function onNextClick() {
//alert(Page_ClientValidate("UserInformation"));
//if (Page_ClientValidate("UserInformation")) {
$("[id$=registration_div]").hide('slide', { direction: 'left' }, 1000);
$("[id$=pick_user_type]").css('position', 'absolute');
$("[id$=pick_user_type]").show('slide', { direction: 'right' }, 1000);
//}
}
function onLeftClick() {
//alert(Page_ClientValidate("UserInformation"));
//if (Page_ClientValidate("UserInformation")) {
$("[id$=pick_user_type]").hide('slide', { direction: 'right' }, 1000);
$("[id$=registration_div]").show('slide', { direction: 'left' }, 1000);
//}
}
</script>
<div id="registration_div">
<table id="registration_table">
<td>
<div id="registration">
<table id="user_information_table">
<tr>
<%--first name and last name--%>
<td>
<asp:TextBox ID="FirstName" runat="server" CssClass="roundedcorner"></asp:TextBox>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkFirstName" runat="server" TargetControlID="FirstName" WatermarkText="First Name" WatermarkCssClass="watermarked roundedcorner" />
<asp:RequiredFieldValidator ID="FirstNameRequired" runat="server" ControlToValidate="FirstName" ErrorMessage="First Name is required." ToolTip="First Name is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkLastName" runat="server" TargetControlID="LastName" WatermarkText="Last Name" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="LastName" runat="server" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="LastNameRequired" runat="server" ControlToValidate="LastName" ErrorMessage="Last Name is required." ToolTip="Last Name is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<%--username--%>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkUsername" runat="server" TargetControlID="Username" WatermarkText="Username" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="UserName" runat="server" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<%--password and confirm pass--%>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkPassword" runat="server" TargetControlID="Password" WatermarkText="Password" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="Password" runat="server" TextMode="Password" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="UserInformation"><font color="red" >*</font></asp:RequiredFieldValidator>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkConfirmPassword" runat="server" TargetControlID="ConfirmPassword" WatermarkText="Confirm Password" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="ConfirmPassword" runat="server" CssClass="roundedcorner" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<%--email and confirm email--%>
<tr>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkEmail" runat="server" TargetControlID="Email" WatermarkText="Email" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="Email" runat="server" Columns="48" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email" ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ForeColor="Red" ControlToValidate="Email" ValidationGroup="UserInformation" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkConfirmEmail" runat="server" TargetControlID="ConfirmEmail" WatermarkText="Confirm Email" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="ConfirmEmail" runat="server" Columns="48" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ConfirmEmail" ErrorMessage="Confirm E-mail is required." ToolTip="Confirm E-mail is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ForeColor="red" ControlToValidate="ConfirmEmail" ValidationGroup="UserInformation" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<%-- location --%>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkLocation" runat="server" TargetControlID="Location" WatermarkText="Location" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="Location" runat="server" Columns="48" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="LocationValidator" runat="server" ControlToValidate="Location" ErrorMessage="Location is required." ToolTip="Location is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<%-- birthdate --%>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkBirthdate" runat="server" TargetControlID="Birthdate" WatermarkText="Birthdate (mm/dd/yyyy)" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="Birthdate" runat="server" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="BirthdayRequired" runat="server" ControlToValidate="Birthdate" ErrorMessage="Birthdate is required." ToolTip="Security question is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
<asp:CompareValidator ErrorMessage="(mm/dd/yyyy)" Display="Dynamic" ID="valcDate" ControlToValidate="Birthdate" Operator="DataTypeCheck" Type="Date" ForeColor="red" runat="server" ValidationGroup="UserInformation"></asp:CompareValidator>
<asp:RangeValidator ID="valrDate" runat="server" ControlToValidate="Birthdate" MinimumValue="12/31/1950" MaximumValue="1/1/2100" Type="Date" Text="Invalid Date" ForeColor="Red" Display="Dynamic" ValidationGroup="UserInformation" />
</td>
</tr>
<tr>
<%-- gender --%>
<td>
<%--<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkGender" runat="server" TargetControlID="Gender" WatermarkText="Birthdate (mm/dd/yyyy)" WatermarkCssClass="watermarked" />--%>
<asp:DropDownList ID="Gender" runat="server" CssClass="roundedcorner">
<asp:ListItem Value="Gender"></asp:ListItem>
<asp:ListItem Value="Male"></asp:ListItem>
<asp:ListItem Value="Female"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator InitialValue="Gender" ID="GenderRequired" runat="server" ControlToValidate="Gender" ErrorMessage="Gender is required." ToolTip="Gender is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="color: Red;">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td>
<asp:CompareValidator ID="comparePasswords" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" ErrorMessage="Your passwords do not match!" ForeColor="red" Display="Dynamic" ValidationGroup="UserInformation" />
<asp:CompareValidator ID="EmailComparitor" runat="server" ControlToCompare="Email" ControlToValidate="ConfirmEmail" ErrorMessage="Your emails do not match!" ForeColor="Red" Display="Dynamic" ValidationGroup="UserInformation" />
<br />
<%--<asp:RegularExpressionValidator ID="PasswordRegExValidator" runat="server" ValidationExpression="^.*(?=.{8,35})(?=.*\d)(?=.*[a-zA-Z]).*$" ForeColor="Red" ControlToValidate="Password" ValidationGroup="UserInformation" ErrorMessage="Your Password must be at least 8 charaters long and contain at least 1 number."></asp:RegularExpressionValidator>--%>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<asp:ImageButton ID="NextButton" ClientIDMode="Static" runat="server" ImageUrl="images/registration/arrowright.png"
Height="50px" onmouseover="this.src='images/registration/arrowrightgreen.png'" onmouseout="this.src='images/registration/arrowright.png'" ValidationGroup="UserInformation" OnClientClick="onNextClick()" AutoPostBack="False" OnClick="NextButton_Click"/>
</div>
<%--STEP 2--%>
<div id="pick_user_type">
<asp:ImageButton ID="LeftButton" runat="server" ImageUrl="images/registration/arrowleft.png"
Height="50px" onmouseover="this.src='images/registration/arrowleftgreen.png'"
onmouseout="this.src='images/registration/arrowleft.png'" ValidationGroup="UserSelectGroup"
OnClientClick="onLeftClick()" AutoPostBack="False"/>
<h2>Almost Done! Tell us a little more information.</h2>
<br />
<div id="pick_user_list">
<strong>Check Those That Apply to Your User Experience</strong>
<asp:CheckBoxList ID="UserTypeList" runat="server">
<asp:ListItem Selected="True" Value="Listener" Enabled="False"> Listener</asp:ListItem>
<asp:ListItem Value="Artist"> Artist</asp:ListItem>
<asp:ListItem Value="Producer"> Producer</asp:ListItem>
<asp:ListItem Value="Promoter"> Promoter</asp:ListItem>
</asp:CheckBoxList>
<br />
<strong>What music artists do you like?</strong>
<input id="artistslikedtags" type="text" class="tags" value="" runat="server" />
<br />
<div id="whatinstruments" style="display: none">
<strong>What instruments do you play?</strong>
<input id="instrumentsplayedtags" type="text" class="tags" value="" disabled="disabled" runat="server"/>
</div>
<br />
<div id="whatrecordingplatforms" style="display: none">
<strong>What recording platforms or equipment do you use?</strong>
<input id="recordingplatformstags" type="text" class="tags" value="" disabled="disabled" runat="server"/>
</div>
<br />
<strong>What mobile platform do you use?</strong><br />
<asp:DropDownList ID="MobilePlatforms" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="iOS">iOS (Apple)</asp:ListItem>
<asp:ListItem Value="Android">Android</asp:ListItem>
<asp:ListItem Value="Windows">Windows</asp:ListItem>
<asp:ListItem Value="Blackberry">Blackberry</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator InitialValue="" ID="MobilePlatformsValidator" runat="server" ControlToValidate="MobilePlatforms" ErrorMessage="This field is required." ToolTip="This field is required." ValidationGroup="UserTypeInformation" ClientIDMode="Static"><font color="red">*</font></asp:RequiredFieldValidator>
<div style="text-align: right">
<asp:Button ID="Finish" runat="server" Text="Finish" ControlToValidate="MobilePlatforms" OnClick="FinishButton_Click" UseSubmitBehavior="False" ValidationGroup="MobilePlatforms" />
</div>
</div>
</div>
Then behind the scenes just a simple method call.
protected void FinishButton_Click(object sender, EventArgs e)
{
MembershipAdapter ma = new MembershipAdapter();
Boolean b = ma.CreateUser(UserName.Text, Email.Text, Password.Text, FirstName.Text, LastName.Text, Gender.Text, Location.Text, Birthdate.Text, MobilePlatforms.Text, "0", "0", "0", artistslikedtags.Value);
}
When I place a breakpoint on the createUser() method, all the text in the objects passed through the method are EMPTY strings!! Does anyone have an idea why this could be?
I have tried ASP.NET AutoPostBack is clearing form data
Are you doing anything during Page_Load that is setting the textbox values to blank? If that's the case you need to wrap these with
if(!Page.IsPostback)
{
//put your initialisation code for them here
}
because otherwise when you submit the form, they will be cleared every time.
Also, unkess I am going blind in my old age, there is no <form> tag in the above code?
You need to learn the various stages of the ASP.NET page lifecycle, as without understanding the basics of this, it will seem very strange of what is actually going on with ASP.NET.
Watch ASP.NET training for beginners : ASP.NET Page Life Cycle and pay specific attention to the Page_Load event, as this is where you will tend to do a lot of your work, especially dynamic content creation.
In your posted example, understanding that you can do certain things the first time the page loads versus on subsequent page requests (called postbacks), then you do the following in your page's Page_Load event:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Do things here that you only want to happen when the page first loads
}
else
{
// Do things here every time the page is requested, except for the first time
}
}
I have two dropdowns categories and subcategories on my page. Also I have an htmleditor on the same page. Below is my aspx
<div class="clearfx">
</div>
<div>
<label>
Description :
</label>
<div style="padding-left: 10px; margin-left: 146px;">
<cc:HtmlEditor ID="Editor" runat="server" Height="600px" Width="850px" EnableViewState="true" />
</div>
</div>
<div class="clearfx">
</div>
<div>
<asp:UpdatePanel runat="server" ID="up" UpdateMode="Always" ChildrenAsTriggers="true">
<ContentTemplate>
<label>Category : </label>
<asp:DropDownList runat="server" ID="Categories" Width="200px" AutoPostBack="True"
OnSelectedIndexChanged="CategoriesSelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvCountry" runat="server" ErrorMessage="Choose a category."
ControlToValidate="Categories" Display="None" EnableTheming="False" EnableViewState="False"
InitialValue="-1" SetFocusOnError="True" ValidationGroup="grpReg"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="rfvCountry_ValidatorCalloutExtender" runat="server"
Enabled="True" TargetControlID="rfvCountry">
</asp:ValidatorCalloutExtender>
<asp:ImageButton runat="server" ID="Refresh" ImageAlign="AbsMiddle"
ImageUrl="~/cdn/images/refresh.png" onclick="RefreshClick"/>
<span class="helptext">(click on refresh image, incase subcategories do not load.)</span>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="clearfx">
</div>
<div>
<label>
Sub Category :
</label>
<asp:DropDownList runat="server" ID="SubCategories" Width="200px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Choose a sub category."
ControlToValidate="SubCategories" Display="None" EnableTheming="False" EnableViewState="False"
InitialValue="-1" SetFocusOnError="True" ValidationGroup="grpReg"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" runat="server" Enabled="True"
TargetControlID="RequiredFieldValidator2">
</asp:ValidatorCalloutExtender>
</div>
What I am doing is that, On the selected index change of the categories dropdown i am populating subcategories. to suppress post back i am using an Update Panel, But my problem is that,the selected index change is fired but the dropdown subcategories does not gets binded. When I remove the update panel, then its works fine, but my html editor looses its value, even having its own and Page enableviewstate = true. Please help me.
My Codebehind methods are:
Dropdown Selected Index Change Event:
protected void CategoriesSelectedIndexChanged(object sender, EventArgs e)
{
if (Categories.SelectedIndex > 0)
{
BindSubCategory(Common.ParseInt(Categories.SelectedItem.Value));
}
else
{
SubCategories.SelectedIndex = 0;
SubCategories.Items.Clear();
}
}
Page Load Event:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
BindCategories();
}
}
private void BindCategories()
{
List<Category> cat = _categoryRepository.GetAll().ToList();
Common.BindDropdown(cat, Categories); // static method
}
public static class Common
{
/// <summary>
///
/// </summary>
/// <param name="list"></param>
/// <param name="ddl"></param>
public static void BindDropdown(IList list, DropDownList ddl)
{
if (list.Count>0)
{
ddl.DataSource = list;
ddl.DataTextField = "Name";
ddl.DataValueField = "Id";
ddl.DataBind();
ddl.Items.Insert(0, new ListItem("---Select---", "-1"));
}
}
}
You need to put the Subcategories in another UpdatePanel and add the proper triggers (set the second panel to trigger on the Categories dropdowns selectedindexchanged event).
<Triggers>
<asp:AsyncPostBackTrigger ControlId="Categories"
EventName="SelectedIndexChanged" />
</Triggers>
sample here
Try this:
<div class="clearfx">
</div>
<div>
<label> Description : </label>
<div style="padding-left: 10px; margin-left: 146px;">
<cc:HtmlEditor ID="Editor" runat="server" Height="600px" Width="850px" EnableViewState="true" />
</div>
</div>
<div class="clearfx">
</div>
<asp:UpdatePanel runat="server" ID="up" UpdateMode="Always" ChildrenAsTriggers="true">
<ContentTemplate>
<div>
<label>Category : </label>
<asp:DropDownList runat="server" ID="Categories" Width="200px" AutoPostBack="True"
OnSelectedIndexChanged="CategoriesSelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvCountry" runat="server" ErrorMessage="Choose a category."
ControlToValidate="Categories" Display="None" EnableTheming="False" EnableViewState="False"
InitialValue="-1" SetFocusOnError="True" ValidationGroup="grpReg"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="rfvCountry_ValidatorCalloutExtender" runat="server"
Enabled="True" TargetControlID="rfvCountry">
</asp:ValidatorCalloutExtender>
<asp:ImageButton runat="server" ID="Refresh" ImageAlign="AbsMiddle"
ImageUrl="~/cdn/images/refresh.png" onclick="RefreshClick"/>
<span class="helptext">(click on refresh image, incase subcategories do not load.)</span>
<div class="clearfx">
</div>
<div>
<label> Sub Category : </label>
<asp:DropDownList runat="server" ID="SubCategories" Width="200px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Choose a sub category."
ControlToValidate="SubCategories" Display="None" EnableTheming="False" EnableViewState="False"
InitialValue="-1" SetFocusOnError="True" ValidationGroup="grpReg"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" runat="server" Enabled="True"
TargetControlID="RequiredFieldValidator2">
</asp:ValidatorCalloutExtender>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>