2017-06-29 112 views
0
int ob=0; 

protected void Button1_Click(object sender, EventArgs e) 

{ 
    ob = Convert.ToInt32(Request.QueryString["value"].ToString()); 

    if (RadioButton1.Checked == true) 
    { 
     ob = ob + 1; 
    } 
    else 
    { 
     ob = ob + 0; 
    } 
    Response.Redirect("result.aspx?value = " + ob); 
} 

例外: - System.NullReferenceException:「對象未設置 到對象的實例。」在asp.net使用的Request.QueryString重定向到另一個頁面asp.net

System.Collections.Specialized.NameValueCollection.this [string] .get 返回null。

+0

可能重複[什麼是NullReferenceException,以及如何解決它?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-doi-i-fix -it) – VDWWD

回答

0
Request.QueryString["value"] 

它返回null。所以當你在null上調用ToString()時,它會引發異常。

+0

在前面的頁面中,我寫了下面的代碼:Response.Write(「ques2.aspx?value =」+ ob);所以變量「值」被攜帶到這個頁面上。 – shelovestocode

+0

Response.Write是關於將字符串寫入HTTP響應輸出流。 看看https://msdn.microsoft.com/en-us/library/1463ysyw(v=vs.110).aspx 所以簡而言之,即使你調用Response.Write(「ques2.aspx?value =「+ ob);這並不意味着'價值'存在於Request.QueryString –

+0

謝謝..以及有關如何解決此問題的任何建議? – shelovestocode

相關問題