• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2501
  • Last Modified:

.NET Form Validation

I've got a .net validator in my form. The validation message fires, but it does not stop the submission.

The submit button is wired to an onClick event in the code behind.
All attached.
<%@ Page language="c#" Src="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebForm1" %>
<%@ Register TagPrefix="Demos" TagName="Css" Src="~/common/ascx/css.ascx"%>
<%@ Register TagPrefix="Demos" TagName="Header" Src="~/common/ascx/hdr.ascx"%>
<%@ Register TagPrefix="Demos" TagName="Footer" Src="~/common/ascx/ftr.ascx"%>
<%@ Register TagPrefix="Demos" TagName="About" Src="~/common/ascx/txt.ascx"%>
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="EN">
  <head>
    <title>Admin Prototype</title>
    <Demos:Css RunAt="server" Id="DemoCss" />

    <link href="../Common/themes/20101/BlackIce/theme.css" type="text/css" rel="stylesheet" />

    <link href="calendarStyle.css" type="text/css" rel="stylesheet" />
    <link href="combobox.css" type="text/css" rel="stylesheet" />
    <link href="inputStyle.css" type="text/css" rel="stylesheet" />    
  </head>
  
  
  <script type="text/javascript">
	 function editGrid(rowId)
  {
   
  	var item = Grid1.getItemFromClientId(rowId);
  	var value = item.getMember('ProductId').get_value();
  	
  	document.getElementById('divInfo').innerHTML = "";
  	document.getElementById('TextBox1').value = item.getMember('Product Name').get_value();
  	document.getElementById('TextBox2').value = item.getMember('ProductId').get_value();
  	//document.getElementById('TextBox3').value = item.getMember('QuantityPerUnit').get_value();
  	inputPrice.set_value(item.getMember('Regular Price').get_value());
  	inputPrice2.set_value(item.getMember('Special Price').get_value());
  	document.getElementById('TextBox4').value = item.getMember('Description').get_value();
  	//document.getElementById('TextBox5').value = item.getMember('UnitsOnOrder').get_value();
  	//document.getElementById('TextBox6').value = item.getMember('ReorderLevel').get_value();
  	document.getElementById('CheckBox1').checked = item.getMember('Active').get_value();
  	//Picker1.setSelectedDate(item.getMember('LastOrderedOn').get_object());
  	setCategory(item);
  	Dialog1.show();
  }
  
  function setCategory(DataItem)
  {
    for(var i = 0; i < ComboBox1.get_itemCount(); i++)
    {
      var item = ComboBox1.getItem(i);
      if(item.get_text() == DataItem.getMember('SubCategoryId').get_text())
      {
      	setTimeout("ComboBox1.selectItemByIndex("+ i +")",50);
        break;
      }
    }
  }

  //function getCalendarValue() {
     // var selectedDate = Picker1.getSelectedDate();
     // var formattedDate = Picker1.formatDate(selectedDate, 'MM/dd/yyyy');
      //return formattedDate;
 // }
  
  function saveItem(){
   	CallBack1.callback('SaveItem',
  			document.getElementById('TextBox1').value, 
  			document.getElementById('TextBox2').value, 
  			ComboBox1.getSelectedItem().get_value(),
  			//document.getElementById('TextBox3').value,
  			inputPrice.get_value(),
  			inputPrice2.get_value(),
  			document.getElementById('TextBox4').value,
  			//document.getElementById('TextBox5').value,
  			//document.getElementById('TextBox6').value,
			document.getElementById('CheckBox1').checked
  			//getCalendarValue()
  			
			);
  }
  
  function insertItem()
  {
    document.getElementById('divInfo').innerHTML = "";
  	document.getElementById('TextBox1').value = "";
  	document.getElementById('TextBox2').value = "NEW";
  	//document.getElementById('TextBox3').value = "";
  	inputPrice.set_value(0);
  	inputPrice2.set_value(0);
  	//document.getElementById('TextBox4').value = "";
  	//document.getElementById('TextBox5').value = "";
  //document.getElementById('TextBox6').value = "";
  	document.getElementById('CheckBox1').checked = false;
  	ComboBox1.selectItemByIndex(0);
  	//Picker1.setSelectedDate(new Date());
  	Dialog1.show();
  }

  function deleteRow(rowId) {
      var item = Grid1.getItemFromClientId(rowId);
  
      if(confirm("Really Delete " + item.getMember('Product Name').get_value() + "?"))
      {
    	     Grid1.deleteItem(item);
      }
  }

 	function editGrid2(item)
 	{
	    Dialog1.Show();
	}
		
    function dialogshow(dialog)
    {
    	  
    }
    function dialogclose(dialog)
    {
    	Grid1.Callback()
    }
    function dialogdrag(dialog)
    {
        
    }
    function dialogdrop(dialog)
    {
        
    }
    function dialogfocus(dialog)
    {
       
    }

    function alignmentchange(sender, eventargs)
    {
        Dialog1.set_x(null);
        Dialog1.set_y(null);
        Dialog1.set_alignment(sender.getSelectedItem().Value);
    }

    function Picker1_OnDateChange() {
        var fromDate = Picker1.getSelectedDate();
        Calendar1.setSelectedDate(fromDate);
    }

    function Calendar1_OnChange() {
        var fromDate = Calendar1.getSelectedDate();
        Picker1.setSelectedDate(fromDate);
    }

    function Button_OnClick(button) {
        if (Calendar1.get_popUpShowing()) {
            Calendar1.hide();
        }
        else {
            var date = Picker1.getSelectedDate();
            Calendar1.setSelectedDate(date);
            Calendar1.show(button);
        }
    }

    function Button_OnMouseUp(event) {
        if (Calendar1.get_popUpShowing()) {
            event.cancelBubble = true;
            event.returnValue = false;
            return false;
        }
        else {
            return true;
        }
    }

   
  </script>

  <body>
    <form id="Form1" method="post" runat="server">
<Demos:Header RunAt="server" Id="DemoHeader" DemoType="Grid" DemoTitle="CCR Grid Edit" />
    <div class="DemoArea" style="width:600px;">
      <ComponentArt:DataGrid id="Grid1"
        AutoTheming="true"
        EditOnClickSelectedItem="false"
        AllowEditing="true" 
        EnableViewState="true"
        RunningMode="Callback"
        ShowHeader="false"
        PageSize="18"
        ImagesBaseUrl="images/grid/"
        LoadingPanelFadeDuration="1000"
        LoadingPanelFadeMaximumOpacity="60"
        LoadingPanelClientTemplateId="LoadingFeedbackTemplate"
        LoadingPanelPosition="MiddleCenter"
        Width="760" Height="420" runat="server">
        <Levels>
          <ComponentArt:GridLevel
            DataKeyField="ProductId"
            EditCommandClientTemplateId="EditCommandTemplate"
            InsertCommandClientTemplateId="InsertCommandTemplate"
            >
            <Columns>
              <ComponentArt:GridColumn AllowEditing="false" DataField="ProductId" />
              <ComponentArt:GridColumn DataField="SubCategoryId" HeadingText="Category" ForeignTable="EcommSubCategories" ForeignDataKeyField="SubCategoryID" ForeignDisplayField="SubCategory" Width="110" Visible="true"/>
              <ComponentArt:GridColumn DataField="ProductID" Visible="false" />
              <ComponentArt:GridColumn DataField="Description" Visible="false" />
			  <ComponentArt:GridColumn DataField="Product Name" HeadingText="Product Name" Width="290"/>
              <ComponentArt:GridColumn DataField="CategoryID" Visible="false" />
              <ComponentArt:GridColumn DataField="SubCategoryID" HeadingText="SubCategory"  Visible="false"/>
              <ComponentArt:GridColumn DataField="Regular Price" Visible="true" FormatString="c"/>
              <ComponentArt:GridColumn DataField="Special Price" Visible="true" FormatString="c"/>
			  <ComponentArt:GridColumn DataField="Active"  ColumnType="CheckBox"/>
			 <%-- <ComponentArt:GridColumn DataField="Active" DataType="System.Boolean" ColumnType="CheckBox"/>
              <ComponentArt:GridColumn DataField="UnitsOnOrder" Visible="false" />
              <ComponentArt:GridColumn DataField="ReorderLevel" Visible="false" />
              <ComponentArt:GridColumn DataField="LastOrderedOn" Visible="false" />
              <ComponentArt:GridColumn DataField="Active" />--%>
			  

			  
			  
              <ComponentArt:GridColumn AllowSorting="false" HeadingText="Edit Command" DataCellClientTemplateId="EditTemplate" EditControlType="EditCommand" Width="100" Align="Center" />
            </Columns>
          </ComponentArt:GridLevel>
        </Levels>
        <ClientTemplates>
          <ComponentArt:ClientTemplate Id="EditTemplate">
            <a href="javascript:editGrid('## DataItem.ClientId ##');">Edit</a> | <a href="javascript:deleteRow('## DataItem.ClientId ##')">Delete</a>
          </ComponentArt:ClientTemplate>
          <ComponentArt:ClientTemplate Id="InsertCommandTemplate">
            <a href="javascript:insertRow();">Insert</a> | <a href="javascript:Grid1.EditCancel();">Cancel</a>
          </ComponentArt:ClientTemplate>
           <ComponentArt:ClientTemplate Id="PreHeaderTemplate">
            <img alt="" src="images/grid/grid_preheader.gif" style="display:block;" />
          </ComponentArt:ClientTemplate>

        <ComponentArt:ClientTemplate Id="PostFooterTemplate">
            <img alt="" src="images/grid/grid_postfooter.gif" style="display:block;" />
          </ComponentArt:ClientTemplate>

          <ComponentArt:ClientTemplate Id="TableHeadingTemplate">
            Try paging, sorting, column resizing, and column reordering.
          </ComponentArt:ClientTemplate>
         
          <ComponentArt:ClientTemplate Id="LoadingFeedbackTemplate">
          <table height="## document.getElementById('Grid1_dom').offsetHeight + 2 ##" width="## document.getElementById('Grid1_dom').offsetWidth ##" bgcolor="#e0e0e0">
          <tr><td valign="center" align="center">
          <table cellspacing="0" cellpadding="0" border="0">
          <tr>
            <td style="font-size:10px;font-family:Verdana;">Loading...&nbsp;</td>
            <td><img src="images/grid/spinner.gif" width="16" height="16" border="0"></td>
          </tr>
          </table>
          </td></tr></table>
          </ComponentArt:ClientTemplate>

          <ComponentArt:ClientTemplate Id="SliderTemplate">
            <table class="SliderPopup" width="200" style="background-color:#ffffff" cellspacing="0" cellpadding="0" border="0">
            <tr>
              <td style="padding:20px;" valign="center" align="center">
                   Page <b>## DataItem.PageIndex + 1 ##</b> of <b>## Grid1.PageCount ##</b>
              </td>
            </tr>
            </table>
          </ComponentArt:ClientTemplate>
        </ClientTemplates>
        

      </ComponentArt:DataGrid>
      <br/>
      <br/>
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
      <tr>
        <td valign="top">
          <span class="hint"><nobr>Click the item's "Edit" link or the "Add Item" button to display the editing Dialog.</nobr></span>        </td>
        <td valign="top"><td>
        <td align="right" valign="top"><input type="button" onclick="javascript:insertItem();" value="Add Item" /></td>
      </tr>
      </table>
       </div>
                 <ComponentArt:Dialog Modal="true" AnimationType="Live" ShowTransition="Fade" AnimationSlide="ExponentialDecelerate" 
            CloseTransition="Fade" ModalMaskImage="images/dialog/alpha.png" AnimationDuration="600" 
            HeaderCssClass="headerCss" Icon="pencil.gif"  Value="Sample Dialog Content" 
            HeaderClientTemplateId="header" Title="ComponentArt Dialog" ContentCssClass="content" 
            FooterClientTemplateId="footer" AllowDrag="true" Alignment="MiddleCentre" ID="Dialog1"
            runat="server" Height="310" Width="458" MinimumWidth="500">
            <ClientEvents>
                <OnShow EventHandler="dialogshow" />
                <OnClose EventHandler="dialogclose" />
                <OnDrag EventHandler="dialogdrag" />
                <OnDrop EventHandler="dialogdrop" />
                <OnFocus EventHandler="dialogfocus" />
              </ClientEvents>  
	<ClientTemplates>
		<ComponentArt:ClientTemplate id="header">
			<table style="filter:alpha(opacity=60);" cellpadding="0" cellspacing="0" border="0" width="458" height="35" onmousedown="Dialog1.StartDrag(event);">
				<tr>
					<td width="9" height="35" style="background-image:url(images/dialog/top-left.png);"></td>
					<td height="35" style="background-image:url(images/dialog/top-mid.png);height:35px !important;" valign="middle" width="409">
						<span style="color:White;font-size:15px;font-family:Arial;font-weight:bold;">Grid Editing Via Dialog</span>
					</td>
					<td width="40" height="35" valign="top" style="background-image:url(images/dialog/top-right.png);">
					  
						<img src="images/dialog/close.png" style="cursor:default;padding-top:4px;" width="32" height="25" style="margin-top:4px;" onmousedown="this.src='images/dialog/close-down.png';" onmouseup="this.src='images/dialog/close-hover.png';" onclick="Dialog1.Close('Close click');" onmouseover="this.src='images/dialog/close-hover.png';" onmouseout="this.src='images/dialog/close.png';"/>
					</td>
				</tr>
			</table>
		</ComponentArt:ClientTemplate>
		
		<ComponentArt:ClientTemplate id="footer">
			<table cellpadding="0" cellspacing="0" width="458" height="7" style="filter:alpha(opacity=60);">
				<tr>
					<td width="9" height="7"><img style="display:block;" src="images/dialog/bottom-left.png"/></td>
					<td style="background-image:url(images/dialog/bottom-mid.png);" width="440"></td>
					<td width="9" height="7"><img style="display:block;" src="images/dialog/bottom-right.png"/></td>
				</tr>
			</table>
		</ComponentArt:ClientTemplate>
	</ClientTemplates>
	<Content>
	<table cellpadding="0" cellspacing="0" width="458">
                  				<tr>
													<td style="background-image:url(images/dialog/left.png);" width="5"></td>
													<td style="background-color:white;font-size:12px;font-family:Arial;">
													<table cellpadding="0" cellspacing="0">
													<tr>
													<td style="padding:10px;">
													<P>
													  <table>
														  <tr><td><STRONG>Product Name:</STRONG></td><td><asp:TextBox id="TextBox1" runat="server" Width="300" />
															  <asp:RequiredFieldValidator ControlToValidate="TextBox1" Text="The name field is required!" runat="server" />
														  </td></tr>
														  <tr>
															  <td><STRONG>Category Name:</STRONG></td><td>            							
											            	<ComponentArt:ComboBox id="ComboBox1" runat="server" 
											            	    EnableViewState="false"
																	    	RunningMode="Client"
																	      CssClass="comboBox" TextBoxEnabled="false"
																	      HoverCssClass="comboBoxHover" SelectedIndex="4"
																	      FocusedCssClass="comboBoxHover"
																	      TextBoxCssClass="comboTextBox"
																	      DropDownCssClass="comboDropDown"
																	      ItemCssClass="comboItem"
																	      ItemHoverCssClass="comboItemHover"
																	      SelectedItemCssClass="comboItemHover"
																	      DropHoverImageUrl="images/dialog/drop_hover.gif"
																	      DropImageUrl="images/dialog/drop.gif"
																	      Width="120" />
																</td>
														  </tr>
														  
														  <tr><td><STRONG>Special Price:</STRONG></td><td>
															<ComponentArt:NumberInput runat="server"
															        ID="inputPrice"
															        CssClass="valid"
															        EmptyCssClass="empty"
															        FocusedValidCssClass="focused-valid"
															        FocusedCssClass="focused"
															        InvalidCssClass="invalid"
															        DisabledCssClass="disabled"
															        NumberType="Currency"
															        MaxLength="15" />
														          </td></tr>
														  <tr><td><STRONG>Regular Price:</STRONG></td><td>
															<ComponentArt:NumberInput runat="server"
															        ID="inputPrice2"
															        CssClass="valid"
															        EmptyCssClass="empty"
															        FocusedValidCssClass="focused-valid"
															        FocusedCssClass="focused"
															        InvalidCssClass="invalid"
															        DisabledCssClass="disabled"
															        NumberType="Currency"
															        MaxLength="15" />
														  </td></tr>
														  
														  <tr>
															  <td><strong>Description:</strong></td>
															  <td><asp:TextBox ID="TextBox4" runat="server" rows="5" TextMode="multiline" Width="300" />
															  </td>
													    </tr>
														  <tr>
														    <td><STRONG>Active:</STRONG></td>
														    <td><asp:CheckBox ID="CheckBox1" runat="server" /></td>
														  </tr>
														  <tr>
															  <td colspan="2">
																<ComponentArt:CallBack id="CallBack1" Debug="false" runat="server">
            													<Content>
            															<asp:PlaceHolder id="ph1" runat="server" />
            															<div style='font-weight:bold;color:red;' id='divInfo' />            													</Content>            											            													
          												</ComponentArt:CallBack>          												</td>
          										</tr>
          									</table>
			    									  <asp:TextBox ID="TextBox2" runat="server" style="visibility:hidden" />
		    									      
			    									  <input type="button" value="Save" onclick='saveItem();' />
													
													</P>													</td>
													</tr>
													</table>
													</td>
													<td style="background-image:url(images/dialog/right.png);" width="5"></td>
													</tr>
													</table>
			<ComponentArt:Calendar runat="server"
			   PopUpZIndex="90212"
		      id="Calendar1"
		      AllowMultipleSelection="false"
		      AllowWeekSelection="false"
		      AllowMonthSelection="false"
		      ControlType="Calendar"
		      PopUp="Custom"		      
		      PopUpExpandControlId="calendar_from_button"
		      CalendarTitleCssClass="title"
		      SelectedDate="2005-9-13"
		      VisibleDate="2005-9-13"
		      ClientSideOnSelectionChanged="Calendar1_OnChange"
		      DayHeaderCssClass="dayheader"
		      DayCssClass="day"
		      DayHoverCssClass="dayhover"
		      OtherMonthDayCssClass="othermonthday"
		      SelectedDayCssClass="selectedday"
		      CalendarCssClass="calendar"
		      NextPrevCssClass="nextprev"
		      MonthCssClass="month"
		      SwapSlide="Linear"
		      SwapDuration="300"
		      DayNameFormat="FirstTwoLetters"
		      PrevImageUrl="images/dialog/cal_prevMonth.gif"
  		      NextImageUrl="images/dialog/cal_nextMonth.gif"
    			/>

		</Content>
	      </ComponentArt:Dialog>
   
	
    <%-- <demos:about id="demoAboutText" AboutFile="~/grid/design/blackice/about.inc" runat="server"/>--%>

   <%-- <demos:footer id="pageFooter" runat="server"/>

     image preload (not necessary but it improves page performance) --%>
    <div style="position:absolute;top:0px;left:0px;visibility:hidden;">
      <img src="images/grid/header_hoverBg.gif" width="0" height="0" alt="" />
      <img src="images/grid/header_activeBg.gif" width="0" height="0" alt="" />
      <img src="images/grid/spinner.gif" width="0" height="0" alt="" />
    </div>
 		
		
		
    </form>

  </body>
</html>

Open in new window

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public class WebForm1 : System.Web.UI.Page
{
  protected ComponentArt.Web.UI.Grid Grid1;
  protected ComponentArt.Web.UI.ComboBox ComboBox1;
  protected System.Web.UI.WebControls.Button Button1; 
  protected System.Data.OleDb.OleDbConnection dbCon; 
  protected ComponentArt.Web.UI.CallBack CallBack1; 
  protected System.Web.UI.WebControls.PlaceHolder ph1;
  
  
  
  private void Page_Load(object sender, System.EventArgs e)
  {
    string conStr = "Provider=SQLOLEDB.1;Password=****************;Persist Security Info=True;User ID=************;Initial Catalog=**********;Data Source=********************";
    dbCon = new System.Data.OleDb.OleDbConnection(conStr); 
    dbCon.Open(); 

    if(!Page.IsPostBack)
    {
      buildGrid();
      Grid1.DataBind();
    }
  }
  
  private bool IsOnWebSite()
  {
    return Request.Url.ToString().ToLower().IndexOf("comp.art") > 0;
  }

  private void CallBack1_Callback(object sender, ComponentArt.Web.UI.CallBackEventArgs e)
  {
    Literal Literal1 = new Literal();
    String retVal = "Updated";
    
  	switch(e.Parameters[0].ToString().ToUpper())
  	{
  		   case "SAVEITEM":
	        saveItem(e.Parameters[1].ToString(), 
                    e.Parameters[2].ToString(), 
                    e.Parameters[3].ToString(),
                    e.Parameters[4].ToString(), 
                    e.Parameters[5].ToString(), 
                    e.Parameters[6].ToString(), 
                    e.Parameters[7].ToString()
                    );
            if(e.Parameters[0].ToString().ToUpper() == "NEW")
                retVal = "Inserted";
             break;
	       case "NEWITEM":
            break;
                        
  	 }
     Literal1.Text = "<div style='font-weight:bold;color:red;' id='divInfo'>Product: " + e.Parameters[1].ToString() + " " + retVal + " - Close Dialog To Complete</div>";
     ph1.Controls.Add(Literal1);
     ph1.RenderControl(e.Output);  
  }

    private void saveItem(string productName, string id, string category,
                          string unitPrice, string unitPrice2, string description, 
                          string active){
                          
		string sql;       
		
			if(id.ToUpper() == "NEW"){
					sql = "insert into EcommProducts ([Product Name], SubCategoryID, [Regular Price], [Special Price], Description, Active, Categoryid, domainID) values(";
                    sql += "'" + productName.Replace("'", "''") + "',";
                    sql += category + ",";
                   // sql += "'" + quantityPerUnit + "',";
                    sql += unitPrice + ",";
                    sql += unitPrice2 + ",";
                    sql += "'" + description + "',";
                   // sql += reorderLevel + ",";
                    //sql += active + "";
                    sql += "(CASE WHEN '"+active+"' = 'true' THEN 'yes' ELSE 'no' END)" + ",";
				   sql +=   175 + ",";
				   sql +=   16  ;
                    sql += ");";
				}
			else{
			  sql = "update ecommProducts set ";
              sql += "[Product Name] = '" + productName.Replace("'","''") + "', ";
			  sql += "SubCategoryId = " + category + ", ";
              //sql += "QuantityPerUnit = '" + quantityPerUnit + "', ";
              sql += "[Regular Price] = " + unitPrice + ", ";
              sql += "[Special Price] = " + unitPrice2 + ", ";
             //sql += "Active = " + (CASE WHEN active = 1 THEN 'yes' ELSE 'no' END)+ " , ";
              //sql += "Active = (CASE WHEN "+active+" = 1 THEN 'yes' ELSE 'no' END) , ";
              sql += "Active = (CASE WHEN '"+active+"' = 'true' THEN 'yes' ELSE 'no' END) , ";
			  
			  //sql += "Active" = '" + (active ? "yes":"no") + "', ";
			  sql += "description = '" + description.Replace("'","''") + "' ";
			  
			  
			  
			  
              //sql += "description = '" + description + "' ";
             // sql += "unitsOnOrder = " + unitsOnOrder + ", ";
              //sql += "reorderLevel = " + reorderLevel + ", ";
             // sql += "discontinued = " + discontinued + ", ";
              //sql += "lastOrderedOn = '" + lastOrderedOn + "' ";
              sql += " where ProductId = " + id;       		
			}
        
        try
		    {
if (!IsOnWebSite())
{
		      System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(sql, dbCon); 
		      cmd.ExecuteNonQuery();
}
		    }
		    catch(Exception ex)
		    {
		      throw new Exception(ex.Message + " " + sql);
		    }		    
		}

  private void buildGrid()
  {
    string sql;       
    sql = "SELECT ProductID, [Product Name], [Regular Price], [Special Price], SubcategoryID, CategoryID, Description, (CASE Active WHEN 'yes' THEN 1 ELSE 0 END) AS Active FROM ecommProducts where domainid = 16 AND CategoryID = 175 order by [product name]"; 
	
	System.Data.OleDb.OleDbDataAdapter daSrc = new System.Data.OleDb.OleDbDataAdapter (sql, dbCon); 
      
    DataTable oTable1 = new DataTable("EcommProducts");
    daSrc.Fill(oTable1); 

    sql = "SELECT * FROM ecommsubCategories where domainid = 16 AND categoryid = 175 order by subcategory"; 
    daSrc = new System.Data.OleDb.OleDbDataAdapter (sql, dbCon); 
      
    DataTable oTable2 = new DataTable("EcommSubCategories");
    daSrc.Fill(oTable2);

    DataSet dsSrc = new DataSet();
    dsSrc.Tables.Add(oTable1);
    dsSrc.Tables.Add(oTable2);

    dsSrc.Relations.Add(dsSrc.Tables["EcommSubCategories"].Columns["SubCategoryId"], dsSrc.Tables["ecommProducts"].Columns["SubCategoryId"]);
      
    Grid1.DataSource = dsSrc;
    
      ComboBox1.DataSource = dsSrc;
      ComboBox1.DataMember = "EcommSubCategories";
      ComboBox1.DataTextField = "SubCategory";
      ComboBox1.DataValueField = "SubCategoryId";
      
      ComboBox1.DataBind();
  }
  
  private void Grid1_DeleteCommand(object sender, ComponentArt.Web.UI.GridItemEventArgs e)
  {
     String sql = "delete from Ecommproducts where DomainID = 16 AND productid = " + e.Item["ProductId"].ToString();
     try
	 {
if (!IsOnWebSite())
{
		      System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(sql, dbCon); 
		      cmd.ExecuteNonQuery();
}
	 }
	 catch(Exception ex)
	 {
		      throw new Exception(ex.Message + " " + sql);
     }		         
  }

  public void OnNeedRebind(object sender, EventArgs oArgs)
  {
    Grid1.DataBind();
  }

  public void OnNeedDataSource(object sender, EventArgs oArgs)
  {
    buildGrid();
  }

  public void OnPageChanged(object sender, ComponentArt.Web.UI.GridPageIndexChangedEventArgs oArgs)
  {
    Grid1.CurrentPageIndex = oArgs.NewIndex;
  }

  public void OnSort(object sender, ComponentArt.Web.UI.GridSortCommandEventArgs oArgs)
  {
    Grid1.Sort = oArgs.SortExpression;
  }

  #region Web Form Designer generated code
	override protected void OnInit(EventArgs e)
	{
		//
		// CODEGEN: This call is required by the ASP.NET Web Form Designer.
		//
		InitializeComponent();
		base.OnInit(e);
	}
	
	/// <summary>
	/// Required method for Designer support - do not modify
	/// the contents of this method with the code editor.
	/// </summary>
	private void InitializeComponent()
	{    
		this.Load += new System.EventHandler(this.Page_Load);      
    Grid1.NeedRebind += new ComponentArt.Web.UI.Grid.NeedRebindEventHandler(OnNeedRebind);
    Grid1.NeedDataSource += new ComponentArt.Web.UI.Grid.NeedDataSourceEventHandler(OnNeedDataSource);
    Grid1.PageIndexChanged += new ComponentArt.Web.UI.Grid.PageIndexChangedEventHandler(OnPageChanged);
    Grid1.SortCommand += new ComponentArt.Web.UI.Grid.SortCommandEventHandler(OnSort);
    Grid1.DeleteCommand += new ComponentArt.Web.UI.Grid.GridItemEventHandler(this.Grid1_DeleteCommand);
    CallBack1.Callback += new ComponentArt.Web.UI.CallBack.CallbackEventHandler(this.CallBack1_Callback);
  }
	#endregion

}

Open in new window

0
webdork
Asked:
webdork
  • 2
1 Solution
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Helo again my friend, the problem is that you must use a ASPNET button, not a html submit button, let me see what can I do, I gues that you want to press the Save button and if your validation is ok then you want to call saveItem(); function...
0
 
webdorkAuthor Commented:
yes exactly. thanks
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hi, sorry the delay, I was busy... to invoke the validation I added this code to the saveItem() function on your client side javascript:
// Validate
ValidatorValidate(RequiredFieldValidator1);
// Exit if not is valid.
if (!RequiredFieldValidator1.isvalid)
    return;

Open in new window


This file (aspx) has the change:
Default12.aspx

Also, you cant rely only on client (javascript) validation, this can be easily bypassed, I recommend in you server side (code behind) function saveItem() add this as it first line to guaranty not empty values saved:
if (string.IsNullOrWhiteSpace(productName))
    return;

Open in new window

Something like this:
private void saveItem(string productName, string id, string category,
                          string unitPrice, string unitPrice2, string description, 
                          string active){

                // Validate
                if (string.IsNullOrWhiteSpace(productName))
                    return;

		string sql;       
............... rest of your code....

Open in new window


I hope this help.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now