.net textbox in gridview, unaware at postback of background-color change from client javascript
In a gridview I have the following Template Field containing a textbox
<asp:TemplateField ShowHeader="true" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Middle" ItemStyle-Width="106px" HeaderText="Actual Order">
<ItemTemplate>
<asp:TextBox runat="server" ID="txtActualOrder" Columns="4" Text='<%#Eval("QtyOrdered")%>'
CausesValidation="true" onBlur='validate(...)'/>
</ItemTemplate>
</asp:TemplateField>
When a user tabs off a cell I validate the quantity entered in the textbox and change the textbox back-color to yellow if valid, red if invalid (in javascript).
I then have a save button which posts back to the server and loops through the gridview. I am able to get the newly entered text value from the textbox, however I am unaware that the cell has changed it's backcolor to yellow. VS indicates the cell is still the default value of white. The if statement below is always false 开发者_如何学Cand VS debugger says the cell is still white. Does anyone know why on the postback I can get the new text value but not the new backcolor of the cell? What would be the best way to mark my gridviewrow record as authorized and then pass that value back to the server on postback? Please don't question my architechure of validating anything on the client side as non best practice. It's a client requirement.
foreach (GridViewRow row in gvProducts.Rows)
{
TextBox tbActualOrder = (TextBox)row.Cells[3].FindControl("txtActualOrder");
if (tbActualOrder != null)
{
if (tbActualOrder.BackColor != System.Drawing.Color.FromName("yellow"))
{}
}
}
The color of the control is not part of the submitted data when a POST occurs. You will need to create a sister hidden field that stores the valid/invalid data. Something like <input type="hidden" name="txtActualOrder_ValidationResults"/>
.
Of course, validating client side to update the UI, and then throwing away the results of that validation and redoing it server side is the correct way to perform validation.
精彩评论