Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CSS
I have written the javascript function to open new window and pass parameter. Then I use request.Querystring method to get the parameter from the popup.
But if it get any null value then it throw exception. The exception is "Object reference not set to an instance of an object.". I have provided condition to recover this problem.
But not work. My code is here :


C#
function strgetStyleNo() {
            var a = $("[id$='ddlStyleNo']").val();
            var b = $("[id$='ddlDefectType']").val();

            var d1 = $("[id$='txtFromDate']").val();
            var d2 = $("[id$='txtToDate']").val();
            if (a != "") {
                window.open("Reports/Smt_StyleWiseReportWindow.aspx?Names=" + a + "", "mywindow", "status=1,toolbar=1, width=900px, height=600px,left=250,top=100");
            }
            if (b != "") {
                window.open("Reports/Smt_StyleWiseReportWindow.aspx?defect=" + b + "", "mywindow", "status=1,toolbar=1, width=900px, height=600px,left=250,top=100");
            }
            if (d1 != "") {
                window.open("Reports/Smt_StyleWiseReportWindow.aspx?dt1=" + d1 + "&dt2"+d2+"", "mywindow", "status=1,toolbar=1, width=900px, height=600px,left=250,top=100");
            }
        }

C#
string strStyleCode = "";
                string defecttype = "";
                if (Request.QueryString["Names"].ToString() != "" || Request.QueryString["Names"].ToString() != null)
                {
                     strStyleCode = Request.QueryString["Names"].ToString();
                }
                else if (Request.QueryString["defect"].ToString() != "" || Request.QueryString["defect"].ToString() != null)
                {
                    defecttype = Request.QueryString["defect"].ToString();
                }
Posted

Try the following changes
C#
if (Request.QueryString["Names"].ToString() != "" || Request.QueryString["Names"].ToString() != null)

TO
C#
if (Request.QueryString["Names"] != null)
{
   if (Request.QueryString["Names"].ToString() != "")
   {
      
   }
}
 
Share this answer
 
Just Reverse your Condition code... Means First Check Query String Null Value than Check Blank ("") Value... Example are below..


C#
if (Request.QueryString["Names"].ToString() != null || Request.QueryString["Names"].ToString() != "")
              {
                   strStyleCode = Request.QueryString["Names"].ToString();
              }
              else if (Request.QueryString["defect"].ToString() != null || Request.QueryString["defect"].ToString() != "")
              {
                  defecttype = Request.QueryString["defect"].ToString();
              }



Thanks
AARIF
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900