How to effectively validate Asp.Net membership forms - asp.net-membership

What are other suggestions and sample code for efficiently validating the Register and/or login page. Perhaps use of jQuery?
I would like to use some ajax to inform the user the email address is in use for example.
Register.aspx
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="CreateUserWizard1" />
<asp:CustomValidator id="CustomValidator1" runat="server" ValidationGroup="CreateUserWizard1"
Display="None" EnableClientScript="False"></asp:CustomValidator>
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" oncreatinguser="Createuserwizard1_CreatingUser">
<WizardSteps>
<asp:CreateUserWizardStep runat="server" >
<ContentTemplate>
<table border="0">
<tr>
<td align="center" colspan="2">
Sign Up for Your New Account</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="ConfirmPasswordLabel" runat="server"
AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"
ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required."
ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>
</td>
<td>
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server"
ControlToValidate="Email" ErrorMessage="E-mail is required."
ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server"
ControlToCompare="Password" ControlToValidate="ConfirmPassword"
Display="Dynamic"
ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep runat="server" />
</WizardSteps>
</asp:CreateUserWizard>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
Register.aspx.cs
protected void Createuserwizard1_CreatingUser(object sender, LoginCancelEventArgs e)
{
CreateUserWizard1.UserName.ToLower();
// Check if the user name exists or email is in use.
CreateUserWizard cuw = (CreateUserWizard)sender;
cuw.Email = cuw.UserName;
TextBox passwordTextBox =
(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Password");
TextBox confirmPasswordTextBox =
(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ConfirmPassword");
CustomValidator1.IsValid = false;
CustomValidator1.ErrorMessage = "I think the email is in use.";
// Save password in the textbox
passwordTextBox.Attributes.Add("Value", cuw.Password);
passwordTextBox.Attributes.Add("Value", cuw.ConfirmPassword);
e.Cancel = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
CustomValidator1.IsValid = false;
CustomValidator1.ErrorMessage = "Hello errors";
}

I ended up using techniques described here http://www.emadibrahim.com/2008/09/08/client-server-side-validation-in-aspnet-mvc/ to validate/

Related

RadScheduler not working on MonthView

I want to show different content to the user depending on the view he is using. For that, i customized the AppointmentTemplate and the AppointmentCreated event. I want also to show appointments with dynamic height, meaning they expand to fill the content but on days its got nothing it shrinks.
Whats happening is that on MonthView, only the header is shown as in the photo:
And here is the DayView: photo
Here is the AppointmentCreated
protected void sched_AppointmentCreated(object sender, AppointmentCreatedEventArgs e) {
using (DBFactory link = new DBFactory()) {
int evtID = int.Parse(e.Appointment.ID.ToString());
if (evtID == 0) {
evtID = SessionManager.Instance.LastInsertedCalendarEventID;
}
CalendarEvent ce = link.GetCalendarEvent(evtID);
Label lblHeader = (Label)e.Container.FindControl("lblHeader");
Label lblDescription = (Label)e.Container.FindControl("lblDescription");
Label lbldates = (Label)e.Container.FindControl("lbldates");
Label lblParticipants = (Label)e.Container.FindControl("lblParticipants");
Label lblLocale = (Label)e.Container.FindControl("lbllocale");
switch (sched.SelectedView) {
case SchedulerViewType.DayView:
lblLocale.Text = string.Format("{0}", ce.EventLocation1.Location);
lblHeader.Text = string.Format("{0} - {1} ", ce.EventType1.EventTypeName, ce.Subject);
lblDescription.Text = string.Format("{0}", ce.Description);
lbldates.Text = string.Format("{0:hh:mm}h - {1:hh:mm}h", ce.StartDate, ce.EndDate);
lblParticipants.Text = string.Format("{0}", link.GetUsernamesFromEvent(evtID));
break;
case SchedulerViewType.WeekView:
case SchedulerViewType.MonthView:
lblLocale.Text = string.Format("{0}", ce.EventLocation1.Location);
lblHeader.Text = string.Format("{0} - {1} ", ce.EventType1.EventTypeName, ce.Subject);
lblDescription.Text = string.Format("{0}", ce.Description);
lbldates.Text = string.Format("{0:hh:mm}h - {1:hh:mm}h", ce.StartDate, ce.EndDate);
lblParticipants.Text = string.Format("{0}", link.GetInitialsFromEvent(evtID));
break;
}
}
}
and here is the complete markup
<tk:RadScheduler ID="sched" runat="server" AppointmentStyleMode="Default" DayEndTime="19:00:00" AllowInsert="true" AllowEdit="true" AllowDelete="true"
EnableDescriptionField="True" FirstDayOfWeek="Monday" LastDayOfWeek="Friday"
ShowNavigationPane="true" ShowFooter="False" StartEditingInAdvancedForm="true"
StartInsertingInAdvancedForm="true" Height="551px"
OnFormCreated="sched_FormCreated"
OnAppointmentCommand="sched_AppointmentCommand"
OnAppointmentCreated="sched_AppointmentCreated"
OnAppointmentDataBound="sched_AppointmentDataBound"
Skin="Web20">
<MonthView AdaptiveRowHeight="true" MinimumRowHeight="50" VisibleAppointmentsPerDay="30"/>
<AdvancedForm Modal="true" />
<ExportSettings OpenInNewWindow="true" FileName="SchedulerExport">
<Pdf PageTitle="Schedule" Author="Telerik" Creator="Telerik" Title="Schedule"></Pdf>
</ExportSettings>
<TimelineView UserSelectable="false" />
<AppointmentContextMenuSettings EnableDefault="true" />
<TimeSlotContextMenuSettings EnableDefault="true" />
<TimeSlotContextMenus>
<tk:RadSchedulerContextMenu ID="SchedulerTimeSlotContextMenu" runat="server">
<Items>
<tk:RadMenuItem Text="New Appointment" Value="CommandAddAppointment" />
</Items>
</tk:RadSchedulerContextMenu>
</TimeSlotContextMenus>
<AppointmentContextMenus>
<tk:RadSchedulerContextMenu runat="server" ID="ContextMenu1">
<Items>
<%--<tk:RadMenuItem Text="Ir para dia" Value="CommandNavigateDay" />--%>
<tk:RadMenuItem Text="Editar" Value="CommandEdit" />
<tk:RadMenuItem Text="Apagar" Value="CommandDelete" />
<%--<tk:RadMenuItem Text="Exportar Para PPF" Value="CommandExport"></tk:RadMenuItem>--%>
</Items>
</tk:RadSchedulerContextMenu>
</AppointmentContextMenus>
<AppointmentTemplate>
<asp:Label runat="server" ID="lblHeader" Font-Bold="true" />
<hr />
<table border="0">
<tr>
<td style=" border-color:transparent;"><span style="font-weight:bold;">Descricao: </span></td>
<td style=" border-color:transparent;"><asp:Label ID="lblDescription" runat="server" /></td>
</tr>
<tr>
<td style=" border-color:transparent;"><span style="font-weight:bold;">Participantes: </span></td>
<td style=" border-color:transparent;"><asp:Label ID="lblParticipants" runat="server" /></td>
</tr>
<tr>
<td style=" border-color:transparent;"><span style="font-weight:bold;">Duracao: </span></td>
<td style=" border-color:transparent;"><asp:Label ID="lblDates" runat="server" /></td>
</tr>
<tr>
<td style=" border-color:transparent;"><span style="font-weight:bold;">Local: </span></td>
<td style=" border-color:transparent;"><asp:Label ID="lblLocale" runat="server" /></td>
</tr>
</table>
</AppointmentTemplate>
<AdvancedInsertTemplate>
<div class="rsAdvancedEdit rsAdvancedModal" style="position: relative; margin-right: -100px">
<div class="rsModalBgTopLeft"></div>
<div class="rsModalBgTopRight"></div>
<div class="rsModalBgBottomLeft"></div>
<div class="rsModalBgBottomRight"></div>
<div class="rsAdvTitle">
<h1 class="rsAdvInnerTitle"><%# Container.Appointment.Owner.Localization.AdvancedNewAppointment %></h1>
<asp:LinkButton runat="server" ID="LinkButton1" CssClass="rsAdvEditClose"
CommandName="Cancel" CausesValidation="false" ToolTip='<%# Container.Appointment.Owner.Localization.AdvancedClose %>'>
<%# Container.Appointment.Owner.Localization.AdvancedClose%>
</asp:LinkButton>
</div>
<div class="rsAdvContentWrapper" style="background-color: #ffffff;">
<table border="0">
<tr>
<td>
<asp:Label runat="server" Text="Sumário" ID="lblSummaryHdr" /></td>
<td colspan="3">
<asp:TextBox ID="txtSubject" runat="server" CssClass="textbox" Columns="60" Text='<%# Bind("Subject") %>' /></td>
<td>
<asp:Label ID="TextBox1" runat="server" Text='<%# Bind("ID") %>' Visible="false" /></td>
</tr>
<tr>
<td>Descrição</td>
<td colspan="3">
<asp:TextBox ID="txtDescription" CssClass="textbox" Columns="60" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox><br />
</td>
</tr>
<tr>
<td>Inicío</td>
<td>
<tk:RadDateTimePicker ID="startInput" SelectedDate='<%# Bind("Start") %>' runat="server"></tk:RadDateTimePicker>
</td>
<td>Fim</td>
<td>
<tk:RadDateTimePicker ID="finishInput" SelectedDate='<%# Bind("End") %>' runat="server"></tk:RadDateTimePicker>
</td>
</tr>
<tr>
<td>Tipo</td>
<td>
<tk:RadComboBox ID="ddlEventType" runat="server" CssClass="combo" />
</td>
<td>Sala</td>
<td>
<tk:RadComboBox ID="ddlLocations" runat="server" CssClass="combo" />
</td>
</tr>
<tr>
<td>Grupos</td>
<td>
<tk:RadComboBox ID="ddlGroups" runat="server" CssClass="combo" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" />
</td>
<td>Usuários</td>
<td>
<tk:RadComboBox ID="ddlUsers" runat="server" CssClass="combo" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" />
</td>
</tr>
</table>
<asp:Panel runat="server" ID="Panel1" CssClass="rsAdvancedSubmitArea">
<div class="rsAdvButtonWrapper">
<asp:LinkButton CommandName="Insert" runat="server" ID="LinkButton2" CssClass="rsAdvEditSave">
<span><%# Container.Appointment.Owner.Localization.Save%></span>
</asp:LinkButton>
<asp:LinkButton runat="server" ID="LinkButton3" CssClass="rsAdvEditCancel" CommandName="Cancel" CausesValidation="false">
<span><%# Container.Appointment.Owner.Localization.Cancel%></span>
</asp:LinkButton>
</div>
</asp:Panel>
</div>
</div>
</AdvancedInsertTemplate>
<AdvancedEditTemplate>
<div class="rsAdvancedEdit rsAdvancedModal" style="position: relative; margin-right: -100px">
<div class="rsModalBgTopLeft"></div>
<div class="rsModalBgTopRight"></div>
<div class="rsModalBgBottomLeft"></div>
<div class="rsModalBgBottomRight"></div>
<div class="rsAdvTitle">
<h1 class="rsAdvInnerTitle"><%# Container.Appointment.Owner.Localization.AdvancedEditAppointment %></h1>
<asp:LinkButton runat="server" ID="LinkButton4" CssClass="rsAdvEditClose"
CommandName="Cancel" CausesValidation="false" ToolTip='<%# Container.Appointment.Owner.Localization.AdvancedClose %>'>
<%# Container.Appointment.Owner.Localization.AdvancedClose%>
</asp:LinkButton>
</div>
<div class="rsAdvContentWrapper" style="background-color: #ffffff;">
<table>
<tr>
<td>Sumário</td>
<td colspan="3">
<asp:TextBox ID="txtSubject" runat="server" CssClass="textbox" Columns="60" Text='<%# Bind("Subject") %>' /></td>
</tr>
<tr>
<td>Descrição</td>
<td colspan="3">
<asp:TextBox ID="txtDescription" CssClass="textbox" Columns="60" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox><br />
</td>
</tr>
<tr>
<td>Inicío</td>
<td>
<tk:RadDateTimePicker ID="RadDateTimePicker1" SelectedDate='<%# Bind("Start") %>' runat="server"></tk:RadDateTimePicker>
</td>
<td>Fim</td>
<td>
<tk:RadDateTimePicker ID="RadDateTimePicker2" SelectedDate='<%# Bind("End") %>' runat="server"></tk:RadDateTimePicker>
</td>
</tr>
<tr>
<td>Tipo</td>
<td>
<tk:RadComboBox ID="RadComboBox1" runat="server" CssClass="combo" />
</td>
<td>Sala</td>
<td>
<tk:RadComboBox ID="ddlLocations" runat="server" CssClass="combo" />
</td>
</tr>
<tr>
<td>Grupos</td>
<td>
<tk:RadComboBox ID="RadComboBox3" runat="server" CssClass="combo" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" />
</td>
<td>Usuários</td>
<td>
<tk:RadComboBox ID="RadComboBox4" runat="server" CssClass="combo" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" />
</td>
</tr>
<tr>
<td>Privado</td>
<td colspan="3">
<asp:CheckBox runat="server" ID="CheckBox1" AutoPostBack="false" Checked="false" />
</td>
</tr>
</table>
<asp:Panel runat="server" ID="Panel2" CssClass="rsAdvancedSubmitArea">
<div class="rsAdvButtonWrapper">
<asp:LinkButton CommandName="Update" runat="server" ID="LinkButton5" CssClass="rsAdvEditSave">
<span><%# Container.Appointment.Owner.Localization.Save%></span>
</asp:LinkButton>
<asp:LinkButton runat="server" ID="LinkButton6" CssClass="rsAdvEditCancel" CommandName="Cancel" CausesValidation="false">
<span><%# Container.Appointment.Owner.Localization.Cancel%></span>
</asp:LinkButton>
</div>
</asp:Panel>
</div>
</div>
</AdvancedEditTemplate>
</tk:RadScheduler>
There is a KB article on this found on the telerik site:
http://www.telerik.com/support/kb/aspnet-ajax/scheduler/auto-expand-the-height-of-the-appointment.aspx

Issue with form:select, all labels are selected

I am using spring 3 JSP tab lib to generate HTML. I have a select box with following code -
<form:select path="categoryList" multiple="false">
<form:option value="" label="--" selected="selected"/>
<form:options items="${categoryList}" itemValue="catId" itemLabel="catName"/>
</form:select>
HTML getting generated is -
<select id="categoryList" name="categoryList">
<option selected="selected" value="">--</option>
<option value="1" selected="selected">S</option>
<option value="2" selected="selected">Ster</option>
<option value="3" selected="selected">ice</option>
<option value="4" selected="selected">Cees</option>
</select>
Issue is all options getting generated has selected="selected" which makes "Cees" selected on page rather then "--". Can someone please let me know ohw to fix this?
complete page -
<form:form modelAttribute="productManagerVO" name="productManager" id="productManager">
<jsp:directive.include file="../common/header.jsp" />
<div class="MainDiv">
<div class="ManagerHeadline">Product Manager</div>
<table cellspacing="2px" cellpadding="0" width="100%">
<tr>
<td width="100%">
<fieldset>
<legend class="checkoutlegend">Category Information</legend>
<table align="left" id="addCategoryTable">
<tr><td><input type="button" id="addCat" value="Add New Category" /></td></tr>
</table>
<c:if test="${not empty productManagerVO.categoryList}">
<table cellspacing="2px" cellpadding="0" class="timeTable" id="categoryTable">
<th>Name</th>
<th>Order</th>
<th>Active</th>
<th> </th>
<c:forEach var="categoryListVO" items="${productManagerVO.categoryList}" varStatus="item">
<tr>
<td><c:out value="${categoryListVO.catName}" /></td>
<td><c:out value="${categoryListVO.catOrder}" /></td>
<td><c:if test="${categoryListVO.categoryActive}">Yes</c:if>
<c:if test="${!categoryListVO.categoryActive}">No</c:if>
</td>
<td>edit</td>
</tr>
</c:forEach>
</table>
</c:if>
</fieldset>
</td>
</tr>
<tr>
<td width="100%">
<fieldset>
<legend class="checkoutlegend">Product Information</legend>
<table align="left" id="addProductTable">
<tr>
<td><input type="button" id="addPro" value="Add New Product"/></td>
</tr>
</table>
<table cellspacing="2px" cellpadding="0" class="timeTable" id="productTable">
<col width="10%" />
<col width="7%" />
<col width="40%" />
<col width="10%" />
<col width="5%" />
<col width="6%" />
<col width="7%" />
<col width="10%" />
<col width="5%" />
<tr>
<th>Name</th>
<th>Subname</th>
<th>Description</th>
<th>Veg</th>
<th>Spicy</th>
<th>Is Active</th>
<th>Price</th>
<th>Category</th>
<th> </th>
</tr>
<c:if test="${not empty productManagerVO.productList}">
<c:forEach var="productListVO" items="${productManagerVO.productList}" varStatus="item">
<tr>
<td><c:out value="${productListVO.fName}" /></td>
<td><c:out value="${productListVO.fSubname}" /></td>
<td><c:out value="${productListVO.fDesc}" /></td>
<td><c:if test="${productListVO.fVeg}">Yes</c:if>
<c:if test="${!productListVO.fVeg}">No</c:if></td>
<td><c:if test="${productListVO.fSpicy}">Yes</c:if>
<c:if test="${!productListVO.fSpicy}">No</c:if></td>
<td><c:if test="${productListVO.fActive}">Yes</c:if>
<c:if test="${!productListVO.fActive}">No</c:if></td>
<td><c:out value="${productListVO.fPrice}" /></td>
<td><c:out value="${productListVO.categoryName}" /></td>
<td><a id="product" href="#editProduct" onclick="editProductData('${productListVO.fId}')">edit</a></td>
</tr>
</c:forEach>
</c:if>
</table>
</fieldset>
</td>
</tr>
</table>
</div>
<div style="display:none">
<div id="addCategory">
<table cellspacing="2px" cellpadding="0" class="adminTable" style="border:1px solid #dadada;">
<tr>
<td style="font-weight:bold;">Category Name</td>
<td><input type="text" id="caddName" /></td>
</tr>
<tr>
<td style="font-weight:bold;">Category Description</td>
<td><input type="text" id="caddDesc" /></td>
</tr>
<tr>
<td style="font-weight:bold;">Category Order</td>
<td><input type="text" id="caddOrder" /></td>
</tr>
<tr>
<td style="font-weight:bold;">Is Active</td>
<td>Yes <input type="radio" value="y" name="catActive"/> No <input type="radio" value="n" name="catActive"/></td>
</tr>
<tr>
<td colspan="2"><input type="button" id="cSave" name="catSave" value="Submit" onclick="addNewCategory();"/></td>
</tr>
</table>
</div>
<div id="editCategory">
<table cellspacing="2px" cellpadding="0" class="adminTable" style="border:1px solid #dadada;">
<tr>
<td style="font-weight:bold;">Category Name</td>
<td><input type="text" id="ceName" name="ceName"/></td>
</tr>
<tr>
<td style="font-weight:bold;">Category Description</td>
<td><input type="text" id="ceDesc" name="ceDesc"/></td>
</tr>
<tr>
<td style="font-weight:bold;">Category Order</td>
<td><input type="text" id="ceOrder" /></td>
</tr>
<tr>
<td style="font-weight:bold;">Is Active</td>
<td><input type="radio" id="ceActiveY" name="cateActive" value="y"/> Yes
<input type="radio" id="ceActiveN" name="cateActive" value="n"/> No</td>
</tr>
<tr><td colspan="2"><input type="button" id="cSave" name="catSave" value="Submit" onClick="editSaveCategory();"/></td>
<td><input type="hidden" id="ceId"/></td>
</tr>
</table>
</div>
<div id="addProduct">
<table cellspacing="2px" cellpadding="0" class="adminTable" style="border:1px solid #dadada;">
<tr>
<td style="font-weight:bold;">Product Name</td>
<td><input type="text" id="paName" /></td>
</tr>
<tr>
<td style="font-weight:bold;">Product SubName</td>
<td><input type="text" id="paSubName" /></td>
</tr>
<tr>
<td style="font-weight:bold;"> Product Description</td>
<td><input type="text" id="paDesc" /></td>
</tr>
<tr>
<td style="font-weight:bold;">Price</td>
<td><input type="text" id="paPrice" /></td>
</tr>
<tr>
<td style="font-weight:bold;">Is Vegetarian</td>
<td>Yes <input type="radio" id="paVeg" name="proVeg" value="y"/> No <input type="radio" id="paVeg" name="proVeg" value="n"/></td>
</tr>
<tr>
<td style="font-weight:bold;">Is Spicy</td>
<td>Yes <input type="radio" id="paSpicy" name="proSpicy" value="y"/> No <input type="radio" id="paSpicy" name="proCpicy" value="n"/></td>
</tr>
<tr>
<td style="font-weight:bold;">Is Active</td>
<td>Yes <input type="radio" id="paActive" name="proActive" value="y"/> No <input type="radio" id="paActive" name="proActive" value="n"/></td>
</tr>
<tr>
<td style="font-weight:bold;">Category</td>
<td>
<form:select path="categoryList" multiple="single">
<form:option value="" label="--"/>
<form:options items="${productManagerVO.categoryList}" itemValue="catId" itemLabel="catName"/>
</form:select>
</td>
</tr>
<tr>
<td colspan="2"><input type="button" id="caSave" name="cataSave" value="Submit"/></td>
</tr>
</table>
</div>
<div id="editProduct">
<table cellspacing="2px" cellpadding="0" class="adminTable" style="border:1px solid #dadada;">
<tr>
<td style="font-weight:bold;">Product Name</td>
<td><input type="text" id="peName" /></td>
</tr>
<tr>
<td style="font-weight:bold;">Product SubName</td>
<td><input type="text" id="peSubName" /></td>
</tr>
<tr>
<td style="font-weight:bold;"> Product Description</td>
<td><input type="text" id="peDesc" /></td>
</tr>
<tr>
<td style="font-weight:bold;">Price</td>
<td><input type="text" id="pePrice" /></td>
</tr>
<tr>
<td style="font-weight:bold;">Is Vegetarian</td>
<td>Yes <input type="radio" id="peVegY" name="proeVeg" value="y"/> No <input type="radio" id="peVegN" name="proeVeg" value="n"/></td>
</tr>
<tr>
<td style="font-weight:bold;">Is Spicy</td>
<td>Yes <input type="radio" id="peSpicyY" name="proeSpicy" value="y"/> No <input type="radio" id="peSpicyN" name="proeSpicy" value="n"/></td>
</tr>
<tr>
<td style="font-weight:bold;">Is Active</td>
<td>Yes <input type="radio" id="peActiveY" name="proeActive" value="y"/> No <input type="radio" id="peActiveN" name="proeActive" value="n"/></td>
</tr>
<tr>
<td style="font-weight:bold;">Category</td>
<td>
<form:select path="categoryList" multiple="single" id="peCat">
<form:option value="" label="--"/>
<form:options items="${productManagerVO.categoryList}" itemValue="catId" itemLabel="catName"/>
</form:select>
</td>
</tr>
<tr><td>
<td colspan="2"><input type="button" id="peSave" name="proeSave" value="Submit" onClick="editSaveProduct();"/></td>
<input type="text" id="peId"/></td>
</tr>
</table>
</div>
</div>
</form:form>
Try removing the selected=selected on your first item. I don't think its necessary as the list will display in the order you specified - unless you want -- to be the default selection if the form is submitted without this select being touched?
Try this:
<form:select path="categoryList" multiple="single">
<form:option value="" label="--"/>
<form:options items="${categoryList}" itemValue="catId" itemLabel="catName"/>
</form:select>
I've only changed the multiple attribute and removed the selected attribute from the option. This works for me...and i think, must also work for you.
edit:
It seems to be okay, only your last <tr> is wrong...you have two <td> in a row, without </td>
<tr>
<td>
<td colspan="2">
<input type="button" id="peSave" name="proeSave" value="Submit" onClick="editSaveProduct();"/>
</td>
<input type="text" id="peId"/>
</td>
</tr>
must be something like
<tr>
<td>
<input type="button" id="peSave" name="proeSave" value="Submit" onClick="editSaveProduct();"/>
</td>
<td colspan="2">
<input type="text" id="peId"/>
</td>
</tr>
Second, why are you using c:out? You can replace <td><c:out value="${categoryListVO.catName}" /></td> with <td>${categoryListVO.catName}</td>...
Third - this construction
<td><c:if test="${productListVO.fActive}">Yes</c:if>
<c:if test="${!productListVO.fActive}">No</c:if></td>
can you replace with
<c:choose>
<c:when test="${productListVO.fActive}">
Yes
</c:when>
<c:otherwise>
No
</c:otherwise>
</c:choose>
I find this way better...the rest seems to be okay, i can't find anything, what can cause the problem. Search for other not properly closed tags. Is there any warnings/messages from the jsp editor?
I had this problem, and after a lot of digging around in Spring I found what was causing it for me. It was something very specific in my case but there is a general point, which is this.
Spring goes to a great deal of trouble to try to work out what the selected option should be. I started digging around in the OptionWriter and then moved down into the SelectedValueComparator. This tries all manner of comparisons to work out if the current option value should be selected. In the end it falls back to the Propertyeditors and Converters (which is where my mistake was).
So I wonder if your CategoryList class had a badly implemented equals method or a converter that doesn't convert properly (mine always converted into the same object)?

How to display the similar information in every view?

I would like to display the information about user's registration state. It should be displayed on every view, but i consider, that writting this code for about 20 times is a bad idea. By the way, this is the code, it works, i guarantee that:
View/RegistrationInfo:
<table width="95%" border="0" cols="2">
<tr>
<td width="50%" height="124"><h2><strong>Simple Blog </strong></h2></td>
<td width="50%" height="124">
#if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account"))
{
<table width="95%" height="86" border="0">
<tr>
<td width="50%" valign="middle">Hello, #System.Web.HttpContext.Current.User.Identity.Name</td>
<td width="50%" valign="middle" align = "right"><input type="submit" value="Exit" /></td>
</tr>
</table>
}
}
else
{
using (Html.BeginForm("LogIn", "Home"))
{
<table width="95%" height="86" border="0">
<tr>
<td width="45%" valign="bottom">Login:</td>
<td width="45%" valign="bottom">Password:</td>
<td width="10%"></td>
</tr>
<tr>
<td width="45%">
<p>
<input type="text" name="login" />
</p>
</td>
<td width="45%">
<p>
<input type="password" name="password" />
</p>
</td>
<td width="10%" align="left">
<input type="submit" value="Enter" />
</td>
</tr>
<tr>
<td width="45%" valign="top">
#Html.ActionLink("Register", "Register", "Account")
</td>
</tr>
</table>
}
}
</td>
</tr>
</table>
<hr align="left" width="100%" size="2" />
As you can see, this view doesn't require to be strongly typed... and i don't know, should I modify any controllers (because, all information is stored in HTML Context), and how. I tried to call
#Html.RenderAction("RegistrationInfo", "Home");
or
#Html.RenderPartial("RegistrationInfo", "Home");
and every time i receive compile error with message about invalid parametres
While Darin's answer perfectly covers your question, I would point out that registration information seems like it's part of your layout more (master page for the .aspx-inclined) than an actual action.
So what I would do (and indeed, do do) is put it either in the header part of your layout in the top right or under your side menu or something, and let the layout handle all the details of rendering it (with a conditional around it to hide it when you're not logged in, so you don't see it on the login screen).
The following should work:
#Html.Partial("~/Views/Home/RegistrationInfo.cshtml")
Or if you are inside a view of the Home controller simply:
#Html.Partial("RegistrationInfo")
Or if you put this partial in ~/Views/Shared/RegistrationInfo.cshtml you will be able to reference with the shorthand syntax.

mvc3 exchange items between listboxes

I have two list boxes in my view with four arrows to exchange the items between them. I am using 4 buttons with type="submit" and handling it in the controller. Is there any way that i can do it with out postback?
<table style="width:90%; text-align:center">
<thead>
<tr>
<th>Unassigned State:</th><th>
</th><th>Assigned State:</th>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
#Html.ListBoxFor(model => model.UnAssignedSelected,
new MultiSelectList(Model.UnAssignedStates, "Id",
"Name", Model.UnAssignedSelected),
new { size = "6" })
</td>
<td valign="top">
<button style=" width:50px" name="button" value="oneRightArrow" type="submit"> > </button><br />
<button style=" width:50px" name="button" value="twoRightArrow" type="submit"> >> </button><br />
<button style=" width:50px" name="button" value="oneLeftArrow" type="submit"> < </button><br />
<button style=" width:50px" name="button" value="twoLeftArrow" type="submit"> << </button>
</td>
<td valign="top">
#Html.ListBoxFor(model => model.AssignedSelected,
new MultiSelectList(Model.AssignedStates, "Id",
"Name", Model.AssignedSelected))
</td>
</tr>
</tbody>
You can use jQuery for that.
Example: http://www.meadmiracle.com/dlb/DLBDocumentation.aspx

Coldfusion forms and image upload with cffile

I'm learning some Coldfusion, and I'm having trouble with this small form based application I'm building for a coworker.
Here is the first page: http://pastebin.com/aLPYHPsF
As you can see, what I want to do is get the user input and take that input and output it to html. The text stuff works fine, but I can't get the image to upload! What I want to do is have the user click upload, get a confirmation, then click submit and they are sent to the generated html (cfm) page. On the page is a resized version of the image they uploaded.
Please tell me what I'm doing wrong! Right now when "upload" is clicked, the form just dumps.
It's because of you forgot to assign enctype="multipart/form-data" to your first cfform. I've edited some of your coding. Check it out.
<cfset strPath = ExpandPath( "./" ) />
<cfset strPath = GetDirectoryFromPath(GetCurrentTemplatePath()) />
<table width="100%">
<tr>
<td align="center">
<cfform name="ecaform" action="ecagenerator.cfm" enctype="multipart/form-data">
<table style="font-family: arial; font-size: 9pt">
<tr><td height="30px" align="center" colspan="2" style="background-color: #020058; color: #FFFFFF; font-family: arial;">
<b>ECA Newsletter Creation Form</b>
</td>
</tr>
<tr><td height="20"></td></tr>
<tr>
<td>Earned from:</td>
<td>
<cfinput
type="radio"
name="earnedfrom"
value="UC">
UC
<cfinput
type="radio"
name="earnedfrom"
value="ECA">
ECA
</td>
</tr>
<tr>
<td>First Name:</td>
<td>
<cfinput
name="firstname">
</td>
</tr>
<tr>
<td>Last Name:</td>
<td>
<cfinput
name="lastname">
</td>
</tr>
<tr>
<td>Instructor's Name:</td>
<td>
<cfinput
name="instructorname">
</td>
</tr>
<tr>
<td>Date (MM/DD/YYYY):</td>
<td>
<cfinput
name="date">
</td>
</tr>
<tr>
<td>Sex:</td>
<td>
<cfinput
type="radio"
name="sex"
value="male">
Male
<cfinput
type="radio"
name="sex"
value="female">
Female
</td>
</tr>
<tr>
<td>Certificate Type:</td>
<td>
<cfinput
type="radio"
name="certtype"
value="Private">
Private
<cfinput
type="radio"
name="certtype"
value="Recreational">
Recreational
<cfinput
type="radio"
name="certtype"
value="Commercial">
Commercial
</td>
</tr>
</table>
<table style="font-family: arial; font-size: 9pt; margin-top: 20 px;">
<tr>
<td>
Upload the photo:
</td>
</tr>
<tr>
<td>
<cfif isDefined("form.fileUpload")>
<cffile action="upload"
fileField="fileUpload"
destination="#strPath#"
accept="image/*">
<cfimage action="resize"
width="200"
height="200"
source="#strPath##file.serverfile#"
destination="#strPath##file.serverfile#"
overwrite="yes">
<img src="<cfoutput>#file.serverfile#</cfoutput>">
</cfif>
</td>
</tr>
<tr>
<td>
<form enctype="multipart/form-data"
method="post">
<input type="file"
name="fileUpload" /><br /><br />
<input type="submit"
value="Submit"
action="ecagenerator.cfm" />
</form>
</td>
</tr>
</table>
<table style="margin-top: 20px;">
<tr>
<td>
<cfinput
type="submit"
name="Submit"
value="Submit">
</td>
</tr>
</table>
</cfform>
</td>
</tr>
</table>
You might want to look into using <cfdiv> for the image upload section. Basically you want the form for image uploading be inside the <cfdiv>, so that the form is submitted through ajax. Have the image form action post to a previewImage.cfm that uses <cffileupload>, validate with isImageFile() if it is an image file, then use <cfimage> to resize it and display a thumbnail (may use action="writetobrowser"). The easiest way to associate the uploaded image with the parent form would be storing the file path in Session I guess, if you don't want to code up extra Javascript.

Resources