我一直在通過很多帖子來解決我的問題,出於某種原因,我嘗試的解決方案都沒有工作。 我只是試圖從我的aspx.cs傳遞一個值(字符串)到我的aspx(html頁面)。如何將aspx.cs中的值傳遞給aspx
這裏是我的嘗試: 我aspx.cs:
public enum httpVerb
{
GET,
POST,
PUT,
DELETE
}
public string endPoint { get; set; }
public httpVerb httpMethod { get; set; }
public string strResponseValue;
public string ResponseREST { get { return strResponseValue; } }
public string makeRequest()
{
strResponseValue = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endPoint);
request.Method = httpMethod.ToString();
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
if (response.StatusCode != HttpStatusCode.OK)
{
throw new ApplicationException("error code: " + response.StatusCode.ToString());
}
//Process the response stream.. (could be JSON...)
using (Stream responseStream = response.GetResponseStream())
{
if (responseStream != null)
{
using (StreamReader reader = new StreamReader(responseStream))
{
strResponseValue = reader.ReadToEnd();
}//End of StreamReader
}
}//end of using ResponseStream
}//End of response
return strResponseValue;
}
,這裏是試驗型動物我在ASPX那樣: <div><%=ResponseREST%></div>
<div><%=strResponseValue%></div>
<div><%=makeRequest()%></div>
這是我的錯誤:
BC30451'ResponseREST'未被聲明。由於其保護級別,它可能無法訪問。
任何幫助將不勝感激。我對c#相當陌生,所以我可能會錯過簡單的東西。
謝謝
你需要指定'get'和'set'值 – Webruster
像這樣? 'public string ResponseREST {get {return strResponseValue; } set {}}'。我試過這個,同樣的錯誤:( – Phyziik
@Phyziik你班上的訪問修飾符是什麼? – RH6