Undefined is not a valid value for int64

Viewed 265

I came across this error recently and I don't understand what to do

There is a hidden filed

<asp:hiddenfield id="hfResourceID" runat="server" value="0">

and I am collecting this value like

long resourceId = Convert.ToInt64(hfResourceID.Value); 

and the error comes here

private void searchGlobal()
{
      enResourceType resourceType =
      Request.QueryString["ResourceGroupType"] != string.Empty
      ? (enResourceType)Enum.ToObject(typeof(enResourceType), 
      Convert.ToInt16(Request.QueryString["ResourceGroupType"]))
      : enResourceType.Both;

      if(resourceType == enResourceType.Network &&
      Request.QueryString["From"] == "GlobalResourceGroupRequest")
      plhCreateNewNetwork.Visible = true;

      string requestID = (Request.QueryString["RequestID"] != null) ? 
      (string)Request.QueryString["RequestID"] : "0";

      grdResources.DataSourceID = "ResourceDataSource";
      ResourceDataSource.SelectMethod = "SearchGlobal";
      ResourceDataSource.SelectParameters.Clear();
      ResourceDataSource.SelectParameters.Add("name", txtName.Text);
      ResourceDataSource.SelectParameters.Add("requestID", requestID);
      ResourceDataSource.SelectParameters.Add("resourceType", resourceType.ToString());
      ResourceDataSource.SelectParameters.Add("folioID", folioID.Text);

      grdResources.DataBind();
}

and javascript function

function folio_OnClick(sourceID, request) {
  var ret = openfolioPopup(resourceID, requestID);

  var txtfolioID = document.getElementById('<%= txtfolioID.ClientID %>');
  var txtfolio = document.getElementById('<%= txtfolio.ClientID %>');
  var txtfolioName = document.getElementById('<%= txtfolioName.ClientID %>');
   
  if (ret != undefined && ret[0] != 0) {
    txtfolioID.value = ret[0];
    txtfolio.value = ret[1];
    txtfolioName.value = ret[1];

    var field = document.getElementById('<%= hfID.ClientID %>');
    field.value = reID;
    __doPostBack('<%= btnfolio.UniqueID %>', '');
  }
}

This line throws error grdResources.DataBind();. I don't understand what to do here? Please help

1 Answers

I figured it out. I changed this

var field = document.getElementById('<%= hfResourceID.ClientID %>');

to this

var field = document.getElementById('<%= hfResourceID.ClientID %>').value;

in javascript function.

Look into this link

   https://stackoverflow.com/questions/13454985/asp-net-set-hiddenfield-a-value-in-javascript
Related