[英]Request.QueryString usage to read Passed array
我無法使用 Request.Querystring 讀取從其他頁面傳遞的數組
//Label1.Text += FID[l]; //Checked the array and it is printing properly.
Response.Redirect("show.aspx?id=" + ID + "&name=" + NAME + "&fileid="
+FID+"&length="+j);
string fid=string.Empty;
if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString["fileid"].ToString())))
{
fid = Request.QueryString["fileid"].ToString();
}
for (int l = 0; l < length; l++)
{
Label1.Text += fid[l]; //Printing wrong array
}
任何人都可以幫我解決這個問題。
如何使用Global.aspx文件而不是參數傳遞來執行此操作。
您的代碼毫無意義,首先如果該代碼都在同一個方法中,那么 Response.Redirect 之后什么都不會運行。
其次假設 Response.Redirect 與其他代碼的方法不同
if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString["fileid"].ToString())))
在上面的行中,您正在對已經是字符串的內容調用 ToString(),然后將其轉換為字符串。 如果 Request.QueryString["fileid"] 是 null 那么這將拋出 null 引用異常。 你應該做:
if (!string.IsNullOrEmpty(Request.QueryString["fileid"]))
第三個fid是一個字符串,Label1.Text是一個字符串。 為什么要逐個字符地循環遍歷字符串,然后將它們添加到末尾的 Label1.Text 中。
最后,fid 將包含作為查詢字符串參數“fileid”傳遞的任何內容,它不能包含其他任何內容。 如果它具有“錯誤”值,則“錯誤”值將在查詢字符串中傳遞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.