Validation in table control - c#

Currently I'm doing a web form and added some textbox for users to insert into the database. It is working alright already, the validation seems to work successfully without any exception or errors. But I need to align the textbox to make it properly displayed on the browser (Mozilla FireFox).
The problem is, my validation IS IN THE TABLE seems not to be working and I keep encountering error that stated my textbox is null, when I clearly filled that textbox with the correct datatype.
Here is my code:
<table>
<tr>
<td> Customer name </td>
<td><asp:TextBox ID="txtCustomerName0" runat="server" display="Dynamic" ValidationGroup="VG"></asp:TextBox></td>
<td class="style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="This field must be filled in"
ControlToValidate="txtCustomerName0"
ValidationGroup="VG" Display="Dynamic"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td> Contact </td>
<td><asp:TextBox ID="txtContact0" runat="server" ValidationGroup="VG"></asp:TextBox></td>
<td>
<asp:CompareValidator ID="CompareValidator9" runat="server"
ControlToValidate="txtContact0" ErrorMessage="Please put correct phone no."
Operator="DataTypeCheck" Type="Integer"
ValidationGroup="VG" Display="Dynamic"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>ProductCode</td>
<td><asp:TextBox ID="txtProductCode0" runat="server" ValidationGroup="VG"></asp:TextBox></td>
<td> </td>
</tr>
<tr>
<td>ProductName</td>
<td><asp:TextBox ID="txtProductName0" runat="server" ValidationGroup="VG"></asp:TextBox></td>
<td> </td>
</tr>
<tr>
<td>Description</td>
<td><asp:TextBox ID="txtDescription0" runat="server" ValidationGroup="VG"></asp:TextBox></td>
<td> </td>
</tr>
<tr>
<td>Address</td>
<td><asp:TextBox ID="txtAddress0" runat="server" ValidationGroup="VG"></asp:TextBox></td>
<td> </td>
</tr>
<tr>
<td>Quantity</td>
<td><asp:TextBox ID="txtQuantity0" runat="server" ValidationGroup="VG"></asp:TextBox></td>
<td>
<asp:CompareValidator ID="CompareValidator10" runat="server"
ControlToValidate="txtQuantity0" ErrorMessage="Please put correct quantity"
Operator="DataTypeCheck" Type="Integer"
ValidationGroup="VG"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>UnitSalePrice</td>
<td><asp:TextBox ID="txtUnitSalePrice0" runat="server" ValidationGroup="VG"></asp:TextBox></td>
<td>
<asp:CompareValidator ID="CompareValidator11" runat="server"
ControlToValidate="txtUnitSalePrice0" ErrorMessage="Please put correct price"
Operator="DataTypeCheck" Type="Currency"
ValidationGroup="VG"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>Amount</td>
<td><asp:TextBox ID="txtAmount0" runat="server" ValidationGroup="VG"></asp:TextBox></td>
<td>
<asp:CompareValidator ID="CompareValidator12" runat="server"
ControlToValidate="txtAmount0" ErrorMessage="Please put correct amount"
Operator="DataTypeCheck" Type="Currency"
ValidationGroup="VG"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>RequiredDate</td>
<td><asp:TextBox ID="txtRequiredDate0" runat="server" ValidationGroup="VG"></asp:TextBox></td>
<td>
<asp:CompareValidator ID="CompareValidator13" runat="server"
ControlToValidate="txtRequiredDate0"
ErrorMessage="Please put correct date format" Operator="DataTypeCheck"
Type="Date" ValidationGroup="VG"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>ConfirmedDate</td>
<td><asp:TextBox ID="txtConfirmedDate0" runat="server" ValidationGroup="VG"></asp:TextBox></td>
<td>
<asp:CompareValidator ID="CompareValidator14" runat="server"
ControlToValidate="txtConfirmedDate0"
ErrorMessage="Please put correct date format"
Operator="DataTypeCheck" Type="Date"
ValidationGroup="VG"></asp:CompareValidator></td>
</tr>
<tr>
<td><asp:Button ID="btnAdd" runat="server" onclick="btnAdd_Click" Text="ADD" ValidationGroup="VG" /></td>
<td><asp:Button ID="btnBack0" runat="server" onclick="btnHome_Click" Text="Back" /></td>
<td></td>
</tr>
</table>

Use the "Width" property for the Alignment

Make css file for that. In the file add one class, for example:
.textbox
{
text-align:center;
}
apply that cssclass="textbox" with you textbox and
you will get textbox align.

Related

ASP.NET - How to create radio button maxtrix

I want create a radio button maxtrix like below picture!
I was tried use Repeate, but data is different between row and column. So i can't set datasource for repeater. Have way to group 2 list, and set datasource for Repeater, show data int Repeater by call Eval("row"), Eval("column") and Eval("mark")
var lstMatrixAnswer = JsonConvert.DeserializeObject<Answer>(json); //Get from json format
var row = lstMatrixAnswer.row.Select(p => p.row).ToList(); //Row datasource
var col= lstMatrixAnswer.column.Select(p => p.answer + "///" + p.mark).ToList(); //Column datasource (i want radio values is "mark")
public class AnswerCol
{
public string answer { get; set; }
public int mark { get; set; }
}
public class AnswerRow
{
public string row { get; set; }
}
public class Answer
{
public List<AnswerRow> row { get; set; }
public List<AnswerCol> column { get; set; }
}
//This is repeater, but i make sure it is impossible.
<asp:Repeater ID="rptAnswer" runat="server">
<HeaderTemplate>
<table class="table table-striped table-hover table-bordered dataTable" id="tblObject">
<thead>
<th style="vertical-align: middle"><%#Eval("col")%></th>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#Eval("answer") %>
</td>
<td>
<input id="Radio1" type="radio" runat="server" value='<%#Eval("mark") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
== Thank for reading ==
I did something like this way way back only using asp.net and javascript
Here i am posting only a little part , hope its enough for you to keep things going
<table width="100%" style="border-collapse:collapse;text-align:center" cellpadding="2" border="0" class="qoptions">
<tr style="font-weight:bold">
<td align="left" width="15%">Function</td>
<td style="color:#b91d47; font-size:large;font-weight:bold; text-align:center">Highly Dissatisfied</td>
<td style="color:#b91d47; font-size:large;font-weight:bold; text-align:center">Dissatisfied</td>
<td style="color:#b91d47; font-size:large;font-weight:bold; text-align:center">Satisfied</td>
<td style="color:#b91d47; font-size:large;font-weight:bold; text-align:center">Highly Satisfied</td>
<td style="font-weight:bold;" align="right"><span style="padding-right:75px">Comments <span class="instructions">(optional)</span></span></td>
</tr>
<tr style="background-color:#FDE6EA" id="BST"> <%--id="F0Q1"--%>
<td align="left" id="F0Name" >BST</td>
<td><asp:RadioButton ID="rbQ1F0_1" runat="server" GroupName="Q1F0" /></td>
<td><asp:RadioButton ID="rbQ1F0_2" runat="server" GroupName="Q1F0" /></td>
<td ><asp:RadioButton ID="rbQ1F0_3" runat="server" GroupName="Q1F0" /></td>
<td><asp:RadioButton ID="rbQ1F0_4" runat="server" GroupName="Q1F0" /></td>
<td align="right"><asp:TextBox ID="txtQ1F0" runat="server" TextMode="MultiLine" Rows="2" Columns="35" onKeyUp="javascript:Count(this);" onChange="javascript:Count(this);" /> </td>
<asp:HiddenField runat="server" ID="Q1F0Val" Value="" />
</tr>
<tr class="altrow" id="F1Q2">
<td align="left" id="F1Name">F1</td>
<td><asp:RadioButton ID="Q2F1_1" runat="server" GroupName="Q2F1" /></td>
<td><asp:RadioButton ID="Q2F1_2" runat="server" GroupName="Q2F1" /></td>
<td ><asp:RadioButton ID="Q2F1_3" runat="server" GroupName="Q2F1" /></td>
<td><asp:RadioButton ID="Q2F1_4" runat="server" GroupName="Q2F1" /></td>
<td align="right"><asp:TextBox ID="txtQ2F1" runat="server" TextMode="MultiLine" Rows="2" Columns="35" onKeyUp="javascript:Count(this);" onChange="javascript:Count(this);" /> </td>
<asp:HiddenField runat="server" ID="Q2F1Val" Value="" />
</tr>
<tr id="F2Q2">
<td align="left" id="F2Name" >F2</td>
<td><asp:RadioButton ID="Q2F2_1" runat="server" GroupName="Q2F2" /></td>
<td><asp:RadioButton ID="Q2F2_2" runat="server" GroupName="Q2F2" /></td>
<td><asp:RadioButton ID="Q2F2_3" runat="server" GroupName="Q2F2" /></td>
<td><asp:RadioButton ID="Q2F2_4" runat="server" GroupName="Q2F2" /></td>
<td align="right"><asp:TextBox ID="txtQ2F2" runat="server" TextMode="MultiLine" Rows="2" Columns="35" onKeyUp="javascript:Count(this);" onChange="javascript:Count(this);" /> </td>
<asp:HiddenField runat="server" ID="Q2F2Val" Value="" />
</tr>
<tr class="altrow" id="F3Q2">
<td align="left" id="F3Name" >F3</td>
<td><asp:RadioButton ID="Q2F3_1" runat="server" GroupName="Q2F3" /></td>
<td><asp:RadioButton ID="Q2F3_2" runat="server" GroupName="Q2F3" /></td>
<td><asp:RadioButton ID="Q2F3_3" runat="server" GroupName="Q2F3" /></td>
<td><asp:RadioButton ID="Q2F3_4" runat="server" GroupName="Q2F3" /></td>
<td align="right"><asp:TextBox ID="txtQ2F3" runat="server" TextMode="MultiLine" Rows="2" Columns="35" onKeyUp="javascript:Count(this);" onChange="javascript:Count(this);"/> </td>
<asp:HiddenField runat="server" ID="Q2F3Val" Value="" />
</tr>
<tr id="F4Q2">
<td align="left" id="F4Name" >F4</td>
<td><asp:RadioButton ID="Q2F4_1" runat="server" GroupName="Q2F4" /></td>
<td><asp:RadioButton ID="Q2F4_2" runat="server" GroupName="Q2F4" /></td>
<td><asp:RadioButton ID="Q2F4_3" runat="server" GroupName="Q2F4" /></td>
<td><asp:RadioButton ID="Q2F4_4" runat="server" GroupName="Q2F4" /></td>
<td align="right"><asp:TextBox ID="txtQ2F4" runat="server" TextMode="MultiLine" Rows="2" Columns="35" onKeyUp="javascript:Count(this);" onChange="javascript:Count(this);"/> </td>
<asp:HiddenField runat="server" ID="Q2F4Val" Value="" />
</tr>
<tr class="altrow" id="F5Q2">
<td align="left" id="F5Name" >F5</td>
<td><asp:RadioButton ID="Q2F5_1" runat="server" GroupName="Q2F5" /></td>
<td><asp:RadioButton ID="Q2F5_2" runat="server" GroupName="Q2F5" /></td>
<td><asp:RadioButton ID="Q2F5_3" runat="server" GroupName="Q2F5" /></td>
<td><asp:RadioButton ID="Q2F5_4" runat="server" GroupName="Q2F5" /></td>
<td align="right"><asp:TextBox ID="txtQ2F5" runat="server" TextMode="MultiLine" Rows="2" Columns="35" onKeyUp="javascript:Count(this);" onChange="javascript:Count(this);"/> </td>
<asp:HiddenField runat="server" ID="Q2F5Val" Value="" />
</tr>
<tr id="F6Q2">
<td align="left" id="F6Name" >F6</td>
<td><asp:RadioButton ID="Q2F6_1" runat="server" GroupName="Q2F6" /></td>
<td><asp:RadioButton ID="Q2F6_2" runat="server" GroupName="Q2F6" /></td>
<td><asp:RadioButton ID="Q2F6_3" runat="server" GroupName="Q2F6" /></td>
<td><asp:RadioButton ID="Q2F6_4" runat="server" GroupName="Q2F6" /></td>
<td align="right"><asp:TextBox ID="txtQ2F6" runat="server" TextMode="MultiLine" Rows="2" Columns="35" onKeyUp="javascript:Count(this);" onChange="javascript:Count(this);"/> </td>
<asp:HiddenField runat="server" ID="Q2F6Val" Value="" />
</tr>
<tr class="altrow" id="F7Q2">
<td align="left" id="F7Name" >F7</td>
<td><asp:RadioButton ID="Q2F7_1" runat="server" GroupName="Q2F7" /></td>
<td><asp:RadioButton ID="Q2F7_2" runat="server" GroupName="Q2F7" /></td>
<td><asp:RadioButton ID="Q2F7_3" runat="server" GroupName="Q2F7" /></td>
<td><asp:RadioButton ID="Q2F7_4" runat="server" GroupName="Q2F7" /></td>
<td align="right"><asp:TextBox ID="txtQ2F7" runat="server" TextMode="MultiLine" Rows="2" Columns="35" onKeyUp="javascript:Count(this);" onChange="javascript:Count(this);"/> </td>
<asp:HiddenField runat="server" ID="Q2F7Val" Value="" />
</tr>
<tr id="F8Q2">
<td align="left" id="F8Name" >F8</td>
<td><asp:RadioButton ID="Q2F8_1" runat="server" GroupName="Q2F8" /></td>
<td><asp:RadioButton ID="Q2F8_2" runat="server" GroupName="Q2F8" /></td>
<td><asp:RadioButton ID="Q2F8_3" runat="server" GroupName="Q2F8" /></td>
<td><asp:RadioButton ID="Q2F8_4" runat="server" GroupName="Q2F8" /></td>
<td align="right"><asp:TextBox ID="txtQ2F8" runat="server" TextMode="MultiLine" Rows="2" Columns="35" onKeyUp="javascript:Count(this);" onChange="javascript:Count(this);"/> </td>
<asp:HiddenField runat="server" ID="Q2F8Val" Value="" />
</tr>
</table>
Example : Q2F8_1 denote Question 2 function 8 and _1 is rating highly disatisfied.
you can use javascript to save 1 , 2 ,3 or 4 to in hidden field which will be your rating for a key .
Access those hidden fields in your c# code and play your code there

Decimal point in "Convert.ToInt" statement causing Format Error?

I have been following this tutorial to help me create a basic shopping basket. When trying to run the code with the below method added which should calculate the TotalPrice & TotalProducts of the basket on the OrderForm, I get the following error:
'System.FormatException' occurred in mscorlib.dll but was not handled in user code. Additional information: Input string was not in a correct format.
pointing at the line
long ProductPrice =
Convert.ToInt64(PriceLabel.Text) *
Convert.ToInt64(ProductQuantity.Text);
In the database, an example of a ProductPrice is "199.99" where as the tutorial only used whole numbers e.g. "199". I am not sure if this is what is causing the issue? If this is the case, how should the code below be modified to include the decimal point too?
I am new to coding, so this is really stressing me out, I really would appreciated some guideance/suggested code changes to overcome this issue
Thanks as ever guys!
private void UpdateTotalBill()
{
long TotalPrice = 0;
long TotalProducts = 0;
foreach (DataListItem item in dlBasketItems.Items)
{
//Finds the price label on pnlMyBasket
Label PriceLabel = item.FindControl("lblPrice") as Label;
//Finds the quantity text box on pnlMyBasket
TextBox ProductQuantity = item.FindControl("txtProductQuantity") as TextBox;
long ProductPrice = Convert.ToInt32(PriceLabel.Text) * Convert.ToInt32(ProductQuantity.Text);
TotalPrice = TotalPrice + ProductPrice;
TotalProducts = TotalProducts + Convert.ToInt32(ProductQuantity.Text);
}
txtTotalPrice.Text = Convert.ToString(TotalPrice);
txtTotalProducts.Text = Convert.ToString(TotalProducts);
}
pnlMyBasket
<asp:Panel ID="pnlMyBasket" runat="server" ScrollBars="Auto" Height="500px" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px" Visible="false">
<table align="center" cellspacing="1">
<tr>
<td align="center" class="auto-style4">
<asp:Label ID="lblAvailableStockAlert" runat="server" ForeColor="Red" Font-Bold="true"></asp:Label>
<asp:DataList ID="dlBasketItems" runat="server" RepeatColumns="3" Font-Bold="False"
Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
Width="551px">
<ItemTemplate>
<div align="left">
<table cellspacing="1" style="border: 1px ridge #9900FF; text-align: center; width: 172px;">
<tr>
<td style="border-bottom-style: ridge; border-width: 1px; border-color: #000000">
<asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName")%>' Style="font-weight: 700"></asp:Label>
</td>
</tr>
<tr>
<td>
<img alt="" src='<%# Eval("ProductImageUrl") %>' runat="server" id="imgProductPhoto" style="border: ridge 1px black;
width: 157px; height: 130px;" />
</td>
</tr>
<tr>
<td>AvailableStock: <asp:Label ID="lblAvailableStock" runat="server" Text='<%# Eval("ProductStock") %>'
ToolTip="Available Stock" ForeColor="Red" Font-Bold="true"></asp:Label>
<br />
Price:<asp:Label ID="lblPrice" runat="server" Text='<%# Eval ("ProductPrice") %>'></asp:Label>
<br /> Quantity Required x
<asp:TextBox ID="txtProductQuantity" runat="server" Width="20px" Height="10px" MaxLength="2" OnTextChanged="txtProductQuantity_TextChanged" AutoPostBack="true" ></asp:TextBox>
<asp:HiddenField ID="hfProductID" runat="server" Value='<%# Eval("ProductID") %>' />
</td>
</tr>
<tr>
<td>
<hr /> <asp:Button ID="btnRemoveFromBasket" runat="server" CommandArgument='<%# Eval("ProductID") %>'
Text="Remove From Basket" Width="100%" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px"
OnClick="btnRemoveFromBasket_Click" CausesValidation="false" />
</td>
</tr>
</table>
</div>
</ItemTemplate>
<ItemStyle Width="33%" />
</asp:DataList>
</td>
</tr>
</table>
</asp:Panel>
pnlOrderForm
<asp:Panel ID="pnlOrderForm" runat="server" ScrollBars="Auto" Height="500px" BorderColor="Black"
BorderStyle="Inset" BorderWidth="1px" Visible="false">
<table style="width: 258px;">
<tr>
<td align="left">
Name:
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtCustomerName" runat="server" Width="231px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtCustomerName"
ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="left">
PhoneNo:
</td>
</tr
<tr>
<td>
<asp:TextBox ID="txtCustomerPhoneNo" runat="server" Width="231px" MaxLength="10"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtCustomerPhoneNo"
ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="left">
EmailID
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtCustomerEmailID" runat="server" Width="231px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtCustomerEmailID"
ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="left">
Address
</td>
</tr>
<tr>
<td align="left">
<asp:TextBox ID="txtCustomerAddress" runat="server" Width="227px" Height="81px"
TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtCustomerAddress"
ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="left">
Total Products :
</td>
</tr>
<tr>
<td align="center">
<asp:TextBox ID="txtTotalProducts" runat="server" ReadOnly="True" Width="231px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtTotalProducts"
ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="left">
Total Price :
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtTotalPrice" runat="server" ReadOnly="True" Width="231px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtTotalPrice"
ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="left">
Payment Mode:
</td>
</tr>
<tr>
<td align="left">
<asp:RadioButtonList ID="rblMethodOfPayment" runat="server">
<asp:ListItem Value="1" Selected="True">1. Collect & Pay In Store</asp:ListItem>
<asp:ListItem Value="2">2. Pay with card</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
<br />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnPlaceOrder" runat="server" OnClick="btnPlaceOrder_Click" Style="font-weight: 700"
Text="PlaceOrder" Width="90px" />
</td>
</tr>
<tr>
<td>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtCustomerEmailID"
ErrorMessage="Please Enter Valid EmailId" ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
</table>
</asp:Panel>
I think you need to convert to decimal, then to long. Like this:
long ProductPrice;
try
{
// hey you never know, someone might just put in an int64 in that textbox!
ProductPrice = Convert.ToInt32(PriceLabel.Text) *
Convert.ToInt32(ProductQuantity.Text);
}
catch
{
decimal tempPrice = Convert.ToDecimal(PriceLabel.Text) *
Convert.ToDecimal(ProductQuantity.Text);
ProductPrice = Convert.ToInt64(tempPrice);
}
Most direct way to how you are currently doing:
var ProductPrice = Convert.ToDecimal(PriceLabel.Text) * Convert.ToDecimal(ProductQuantity.Text);
this will throw an exception if the value cannot be converted to a decimal. Decimal.TryParse() would be better.
https://msdn.microsoft.com/en-us/library/system.decimal.tryparse(v=vs.110).aspx

ASP.NET form validation triggered too soon

I have a two-step form that I set up with validation on the fields.
The validation for the first two fields (first name / last name) works as desired.
However the last two fields (user/password) get validated two soon.
I would like the user / password fields to get validate only on "submit button" click...
Here's a working example and my code.
www.smithy.somee.com
<script language="javascript" type="text/javascript">
$(document).ready(function () {
if (Page_ClientValidate("personalGroup")) {
$('#form-part-1').hide();
$('#form-part-2').fadeIn();
}
if (Page_ClientValidate("accountGroup")) {
$('#form-part-2').hide();
}
});
</script>
<form id="signup" runat="server">
<div>
<table id="validators">
<tr>
<td>
<asp:ValidationSummary ID="personalGroupSummary" runat="server" ValidationGroup="personalGroup" />
<asp:ValidationSummary ID="accountGroupSummary" runat="server" ValidationGroup="accountGroup" />
</td>
</tr>
</table>
<table id="form-part-1">
<tr>
<td>First Name:</td>
<td><asp:TextBox ID="txtFname" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Last Name:</td>
<td><asp:TextBox ID="txtLname" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="continue" runat="server" causesvalidation="true" validationgroup="personalGroup" Text="Continue" />
</td>
</tr>
</table>
<table id="form-part-2">
<tr>
<td>Username:</td>
<td><asp:TextBox ID="txtUser" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Password:</td>
<td><asp:TextBox ID="txtPass" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSubmit" runat="server" validationgroup="accountGroup" Text="Submit" OnClick="btnSubmit_Click" />
</td>
</tr>
</table>
<!-- output -->
<table>
<tr>
<td>First: </td>
<td><asp:Label ID="lblFname" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td>Last:</td>
<td><asp:Label ID="lblLname" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td>User:</td>
<td><asp:Label ID="lblUser" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td>Pass:</td>
<td><asp:Label ID="lblPass" runat="server" Text=""></asp:Label></td>
</tr>
</table>
</div>
<!-- validators -->
<asp:requiredfieldvalidator id="fvFname" runat="server" validationgroup="personalGroup" Display="None" ControlToValidate="txtFname" ErrorMessage='"First Name" is required'></asp:requiredfieldvalidator>
<asp:requiredfieldvalidator id="fvLname" runat="server" validationgroup="personalGroup" Display="None" ControlToValidate="txtLname" ErrorMessage='"Last Name" is required'></asp:requiredfieldvalidator>
<asp:requiredfieldvalidator id="fvUser" runat="server" validationgroup="accountGroup" Display="None" ControlToValidate="txtUser" ErrorMessage='"Username" is required'></asp:requiredfieldvalidator>
<asp:requiredfieldvalidator id="fvPass" runat="server" validationgroup="accountGroup" Display="None" ControlToValidate="txtPass" ErrorMessage='"Password" is required'></asp:requiredfieldvalidator>
<!-- validators -->
</form>
try adding EnableClientScript="False" to your validators
<asp:requiredfieldvalidator id="fvFname" runat="server"
EnableClientScript="False"
validationgroup="personalGroup" Display="None"
ControlToValidate="txtFname"
ErrorMessage='"First Name" is required'>
</asp:requiredfieldvalidator>
It turns out that Panel controls is the answer to my issue. I found a solution on this website. (compliments of Doug Seven). Built it and tested and works like a charm.
http://devproconnections.com/database-development/create-multistep-forms

Textfield clears after calendar control postback

I have 3 text fields on my page and one calendar control. After I fill in the 3 text boxes, then click a date on the calendar control, the bottom textfield clears out, losing its value. The other 2 text boxes have their values available and do not get cleared. The textboxes all have the same properties, but I can't figure out how to keep the value in the third textbox.
<table class="auto-style2" align="center">
<tr>
<td class="auto-style4" style="text-align: right">Project Name:</td>
<td style="text-align: left">
<asp:TextBox ID="TxtProjectName" runat="server" height="32px" width="211px" MaxLength="50" OnTextChanged="TxtProjectName_TextChanged" onKeyUp="Count(this,50)" onChange="Count(this,50)" TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TxtProjectName" ErrorMessage="Field is required"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
<table class="auto-style2" align="center">
<tr>
<td class="auto-style4" style="text-align: right">Project Description:</td>
<td style="text-align: left">
<asp:TextBox ID="TxtDescription" runat="server" height="45px" width="211px" TextMode="MultiLine" OnTextChanged="TxtDescription_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TxtDescription" ErrorMessage="Field is required"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style4" style="text-align: right">Contact Name:</td>
<td style="text-align: left">
<asp:TextBox ID="TxtContactName" runat="server" Width="203px" OnTextChanged="TxtContactName_TextChanged" Height="16px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TxtContactName" ErrorMessage="Field is required"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style5">Business Area:</td>
<td class="auto-style3">
<asp:DropDownList ID="DDLBusinessArea" runat="server" style="text-align: left">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="auto-style4" style="text-align: right">Priority:</td>
<td style="text-align: left">
<asp:DropDownList ID="DDLPriority" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="auto-style4" style="text-align: right">Desired Completion Date:</td>
<td style="text-align: left">
<asp:Calendar ID="Calendar1" runat="server">
<SelectedDayStyle Font-Bold="True" />
<TodayDayStyle ForeColor="#3333FF" />
</asp:Calendar>
</td>
</tr>
Its the TxtContactName that clears.

Remove spacing of label in specified design sample

I have following design:
Code for it:
<table width="70%" align="center" class ="TableBorder">
<tr>
<td colspan="2" class="Heading" align="center">
Add Client
</td>
</tr>
<tr>
<td class="NormalText" align="right">
Client Name:
</td>
<td align="left">
<asp:TextBox ID="txtClientName" runat="server" CssClass="ThinTextBox"></asp:TextBox>
<asp:Label ID="lblAgentName0" runat="server" ForeColor="#FF3300" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td class="NormalText" width="40%" align="right">
Client Login Email ID:
</td>
<td align="left">
<asp:TextBox ID="txtClientID" runat="server" CssClass="ThinTextBox"></asp:TextBox>
<asp:Label ID="lblAgentName1" runat="server" ForeColor="#FF3300" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td class="NormalText" align="right">
Client Password:
</td>
<td align="left">
<asp:TextBox ID="txtClientPwd" runat="server" CssClass="ThinTextBox"></asp:TextBox>
<asp:Label ID="lblAgentName2" runat="server" ForeColor="#FF3300" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td align="right" class="NormalText">
Contact No.:</td>
<td align="left">
<asp:TextBox ID="txtContactNo" runat="server" CssClass="ThinTextBox"></asp:TextBox>
<asp:Label ID="lblAgentName3" runat="server" ForeColor="#FF3300" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td align="right" class="NormalText" valign="top" >
Address:</td>
<td align="left">
<asp:TextBox ID="txtAddress" runat="server" CssClass="ThinTextBox"
Height="100px" TextMode="MultiLine" Width="200px"></asp:TextBox>
<asp:Label ID="lblAgentName4" runat="server" ForeColor="#FF3300" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td align="right" class="NormalText" width="30%">
</td>
<td align="left">
<asp:Button ID="btnSave" runat="server" CssClass="ButtonColor" Text="Save" />
<asp:Button ID="btnCancel" runat="server" CssClass="ButtonColor"
Text="Cancel" />
</td>
</tr>
</table>
I just wanted to remove spacing between marked area of Address textbox and "*" label.
I tried to give property as valign="top" to label, but its not accepting it.
Please help me.
try this
add style="vertical-align:top;" to label
<asp:Label ID="lblAgentName4" runat="server" ForeColor="#FF3300" Text="*" style="vertical-align:top;"></asp:Label>
Try this one,
<table width="70%" align="center" class="TableBorder">
<tr>
<td colspan="3" class="Heading" align="center">
Add Client
</td>
</tr>
<tr>
<td class="NormalText" align="right">
Client Name:
</td>
<td align="left" colspan="2">
<asp:TextBox ID="txtClientName" runat="server" CssClass="ThinTextBox"></asp:TextBox>
<asp:Label ID="lblAgentName0" runat="server" ForeColor="#FF3300" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td class="NormalText" width="40%" align="right">
Client Login Email ID:
</td>
<td align="left" colspan="2">
<asp:TextBox ID="txtClientID" runat="server" CssClass="ThinTextBox"></asp:TextBox>
<asp:Label ID="lblAgentName1" runat="server" ForeColor="#FF3300" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td class="NormalText" align="right">
Client Password:
</td>
<td align="left" colspan="2">
<asp:TextBox ID="txtClientPwd" runat="server" CssClass="ThinTextBox"></asp:TextBox>
<asp:Label ID="lblAgentName2" runat="server" ForeColor="#FF3300" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td align="right" class="NormalText">
Contact No.:
</td>
<td align="left" colspan="2">
<asp:TextBox ID="txtContactNo" runat="server" CssClass="ThinTextBox"></asp:TextBox>
<asp:Label ID="lblAgentName3" runat="server" ForeColor="#FF3300" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td align="right" class="NormalText" valign="top">
Address:
</td>
<td align="left" class="style1" valign="top">
<asp:TextBox ID="txtAddress" runat="server" CssClass="ThinTextBox" Height="100px"
TextMode="MultiLine" Width="200px"></asp:TextBox>
</td>
<td align="left" valign="top">
<asp:Label ID="lblAgentName4" runat="server" ForeColor="#FF3300" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td align="right" class="NormalText" width="30%">
</td>
<td align="left" colspan="2">
<asp:Button ID="btnSave" runat="server" CssClass="ButtonColor" Text="Save" />
<asp:Button ID="btnCancel" runat="server" CssClass="ButtonColor" Text="Cancel" />
</td>
</tr>
</table>
you must use text vertical-align: text-top; in your css for td like this:
<td align="left" style="vertical-align: text-top;">
<asp:TextBox ID="txtAddress" runat="server" CssClass="ThinTextBox"
Height="100px" TextMode="MultiLine" Width="200px"></asp:TextBox>
<asp:Label ID="lblAgentName4" runat="server" ForeColor="#FF3300" Text="*"></asp:Label>
</td>
Because your asp renders your Label control to html span element, and for spans need text-top style/

Categories

Resources