Solved

.net call back error

Posted on 2011-09-26
5
822 Views
Last Modified: 2012-05-12
getting call back error: <CallbackError><![CDATA[Index was outside the bounds of the array.]]></CallbackError> when running SAVEITEM.

Need a better way to debug also.
<%@ Page language="c#" Src="banners.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="css/calendarStyle.css" type="text/css" rel="stylesheet" />
    <link href="css/combobox.css" type="text/css" rel="stylesheet" />
    <link href="css/inputStyle.css" type="text/css" rel="stylesheet" />    
  </head>
  
  
  <script type="text/javascript">
	 function editGrid(rowId)
  {
   
  	var item = Grid1.getItemFromClientId(rowId);
  	var value = item.getMember('ImageID').get_value();
  	
  	document.getElementById('divInfo').innerHTML = "";
  	document.getElementById('TextBox1').value = item.getMember('Title').get_value();
	document.getElementById('TextBox2').value = item.getMember('ImageID').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('Display').get_value();
  	//Picker1.setSelectedDate(item.getMember('LastOrderedOn').get_object());
  	//setCategory(item);
  	Dialog1.show();
  }
  

  //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, 
  			//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('TextBox4').value = "NEW";
  	//document.getElementById('TextBox3').value = "";
  	//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="ImageId"
            EditCommandClientTemplateId="EditCommandTemplate"
            InsertCommandClientTemplateId="InsertCommandTemplate"
            >
            <Columns>
              <ComponentArt:GridColumn AllowEditing="false" DataField="Imageid" Visible="false"/>
              <ComponentArt:GridColumn DataField="ImageID" Visible="false" />
              <ComponentArt:GridColumn DataField="Description" Visible="false" />
			  <ComponentArt:GridColumn DataField="ImageName" DataCellClientTemplateId="ImageNameTemplate" HeadingText="Image Name" Width="290"/>
			  <ComponentArt:GridColumn DataField="Title"  />
			  <ComponentArt:GridColumn DataField="Display"  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="dg/images/grid/grid_preheader.gif" style="display:block;" />
          </ComponentArt:ClientTemplate>


<ComponentArt:ClientTemplate Id="ImageNameTemplate"> 
 <img alt="xxxyy" src="../gallery/thumbs/## DataItem.GetMember('ImageName').Value ##">
 </ComponentArt:ClientTemplate>


        <ComponentArt:ClientTemplate Id="PostFooterTemplate">
            <img alt="" src="dg/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="dg/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="600" 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="509">
						<span style="color:White;font-size:15px;font-family:Arial;font-weight:bold;">Edit Product</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="602"></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>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="true" 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="dg/images/grid/header_hoverBg.gif" width="0" height="0" alt="" />
      <img src="dg/images/grid/header_activeBg.gif" width="0" height="0" alt="" />
      <img src="dg/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=xxxxxxxxx;Persist Security Info=True;User ID=xxxxxxxxxxx;Initial Catalog=xxxxxxxxxxxxx;Data Source=xxxxxxxxxxxxxx";
    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()
                    );
            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 Title, string id, 
                          string description, 
                          string display){
                          
		
		string sql;       
		
			if(id.ToUpper() == "NEW"){
					sql = "insert into EcommImages (Title, Description, Display, domainID) values(";
                    sql += "'" + Title.Replace("'", "''") + "',";
                    sql += "'" + description + "',";
                    sql += "(CASE WHEN '"+display+"' = 'true' THEN 'yes' ELSE 'no' END)" + ",";
				   sql +=   103  ;
                    sql += ");";
				}
			else{
              sql += "title = '" + Title.Replace("'","''") + "', ";
			  sql += "Display = (CASE WHEN '"+display+"' = 'true' THEN 'yes' ELSE 'no' END) , ";
			  sql += "description = '" + description.Replace("'","''") + "' ";
			  sql += " where ImageId = " + 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]"; 
	
    sql = "SELECT * FROM ecommimages where domainid = 103 order by imageid"; 
	
	System.Data.OleDb.OleDbDataAdapter daSrc = new System.Data.OleDb.OleDbDataAdapter (sql, dbCon); 
      
    DataTable oTable1 = new DataTable("Ecommimages");
    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.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
Comment
Question by:webdork
  • 2
5 Comments
 

Author Comment

by:webdork
Comment Utility
thank you
0
 
LVL 16

Accepted Solution

by:
hjgode earned 500 total points
Comment Utility
Hello

I will try to help:

in your asp you have

  function saveItem(){
         CallBack1.callback('SaveItem',
                    document.getElementById('TextBox1').value
                    //document.getElementById('TextBox2').value,
                    //document.getElementById('TextBox4').value
                    //document.getElementById('TextBox5').value,
                    //document.getElementById('TextBox6').value,
                  //document.getElementById('CheckBox1').checked
                    //getCalendarValue()
                    
                  );

This function actually invokes SaveItem callback with only ONE arg (TextBox1.value). BUT your saveItem call back code is:

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()
                    );
            if(e.Parameters[0].ToString().ToUpper() == "NEW")
                retVal = "Inserted";
             break;
               case "NEWITEM":
            break;
                       
         }

This code is looking for 4 arguments.

As it called with only one arg you get the IndexOutOfRange error.

To avoid this, you have to ensure that your use the correct number of args before you call from asp into the code or make your code more robust and do not rely on getting the number of args you expected.

One approach would be to verify the number of args like this:
                   case "SAVEITEM":
    If(e.Parameters.Length==5){
                saveItem(e.Parameters[1].ToString(),
                    e.Parameters[2].ToString(),
                    e.Parameters[3].ToString(),
                    e.Parameters[4].ToString()
                    );
    }
   else
   {
      //your code to handle a callback with to less arguments
   }

0
 

Author Closing Comment

by:webdork
Comment Utility
Excellent solution. Concise and complete.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now