0
我需要在服務器端獲取用戶屏幕分辨率,並根據分辨率調整控件大小。我有asp:HiddenField
我想存儲分辨率。調用page_load表單jquery ajax客戶端
<asp:HiddenField runat="server" ID="hdnScreenResolution" />
我有jQuery的AJAX調用提交決議:
$(document).ready(function() {
width = screen.width;
height = screen.height;
$.ajax({
url: "Questionnaire.aspx/WindowResolutionSet",
data: "{ 'width': '" + width + "', 'height' : '" + height + "'}",
type: "POST",
contentType: "application/json; charset=utf-8",
sucess: function (msg) { alert("it works"); },
error: function() { alert("error"); }
});
});
而Web方法吧:
[WebMethod]
public static bool WindowResolutionSet(string width, string height)
{
return true;
}
從WindowResolutionSet我無法訪問網頁上的服務器控件。
而sucess: function (msg) { alert("it works");
不會觸發。
我想以填充sucess
width
和height
,然後從Page_Load()
訪問,但sucess
不火。 error
也不能執行。
必須有更有效的方式,但我不知道它=/
它的答案),但仍好奇如何通過jQuery的AJAX做) – makambi
事實上,如果沒有這種性質,我想你會有種砍來執行。您必須調用此webmethod,在視圖狀態或用戶會話中存儲檢測到的分辨率。然後重新加載整個頁面以再次觸發page_load事件,您可以在其中恢復視圖狀態或會話變量。沒有這個屬性那麼簡單。 –
我會用你的方法,謝謝)這種好奇心只是出於教育的原因) 會在空閒時間做 – makambi