0

ASP.NET Web フォーム アプリケーションのコード ビハインドで、ページ メソッドへのデータを使用して Ajax 要求を作成しています。aspx ページに Panel コントロールがありますが、その ID を持つ Page Method からコントロールを取得できません。Page_Loadイベントで手に入るけど。ページメソッドから Panel コントロールを取得するにはどうすればよいですか?それは不可能ですか、それとも代替手段ですか?

<asp:Panel ID="pnlImages" runat="server"></asp:Panel>

<script type="text/javascript">
    function GetProductId() {
        $.ajax({
            type: "POST",
            url: "Default.aspx/GenerateQrCode",
            data: "{'Products':" + JSON.stringify(data) + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(xhr.responseText);
                alert(thrownError);
            },
            success: function (msg) {
                alert('Success');
            }
        });
    }
</script>
[WebMethod]
public static void GenerateQrCode(List<Product> Products)
{
    foreach(var product in Products)
    {
        string qrCodeLocation = products.Where(pid=>pid.ProductId == product.ProductId).Select(s=>s.QrCode).FirstOrDefault().ToString();

        Image image = new Image();
        image.ID = product.ProductId.ToString();
        image.ImageUrl = qrCodeLocation;
        //Cannot get 'pnlImages' here
    }
}
4

1 に答える 1

0

WebMethod通常のページ メソッドと同じフローに従っていないため、それを行うことはできません。インスタンスメソッドではなく静的です。

クライアントに情報を返し、javascript を使用してそこでイメージを作成する必要があります。

于 2013-05-31T16:12:45.250 に答える