Link to home
Start Free TrialLog in
Avatar of tech_question
tech_question

asked on

why am I unable to see these hidden field values in PostBack ?

I need to call a codebehind method and pass some parameters.
below is my code, the hidden field values are null eventhough I am setting them using javascript. what am I doing wrong ?

I get an exception - object reference not set to null  at  - Request.Params.Get("hidID").ToString()

why is it ?
-- aspx page 
function confirmDelete(id)
       {
       
            if(confirm("Do you want to Delete this Invoice?"))
            {
              
               //document.forms[0].hidAction.Value = "DELETE";
               //document.forms[0].hidID.Value     = id;
               document.getElementById('<%= hidAction.ClientID %>').Value = "DELETE";
               document.getElementById('<%= hidID.ClientID %>').Value = id;
               document.getElementById('<%= btnDelete.ClientID %>').click();
               return true;
               //document.getElementById("hidID").value = id;
 
            }
   
            
         
      }
 
 
codebehind
--------------
 
  if (Page.IsPostBack)
        {
            long InvoiceID = Convert.ToInt64(Request.Params.Get("hidID").ToString());
            if (Request["hidAction"].ToString().ToUpper() == "DELETE")
            {
                this.DeleteInvoice(InvoiceID);
            }
 
        }

Open in new window

Avatar of Kalpana_Natarajan
Kalpana_Natarajan

In the aspx page, you are retrieving the value of the hidId.ClientID control, but you are not adding this to the query string of the same page.
You need to call the page from javascript as http://<PageAddress>?hidID=<Value retreived in the javascript method> when the form is submitted.

The null reference is thrown because the name value pair of hidID is missing in the Request String, not because hidden field value didn't work.

Please let me know if anything is unclear.

Regards,
Kalpana
Avatar of tech_question

ASKER

I do not want the users to see the value - I am not passing them as querystring but as form hidden values. Does that make sense ?
SOLUTION
Avatar of ajolly
ajolly
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial