开发者

To get controls inside static function

I am calling function in codebehind from javascript using webservice.

function  GetAdmissionType()
        {
            InitComponents();
            var type="";
            type=document.getElementById(dlAdmissionType.id).value;
             document.getElementById(hdnAdmissionType.id).value=document.getElementById(dlAdmissionType.id).value;

             else if(type=="2")
             {
                   InitComponents();
                   ViewResettingPanel()
                   makeFavorite(1);

             }
    }



       function makeFavorite(id) {
    PageMethods.SaveInfo(id, CallSuccess, CallFailed);
}

// This开发者_JAVA技巧 will be Called on success
function CallSuccess(res, id) {
alert(destCtrl);
}

// This will be Called on failure
function CallFailed(res) {
alert(res.get_message());
}

Following is my code in codebehind

[System.Web.Services.WebMethod]
    public static void SaveInfo(String Id)
    {

       //to get textbox in form
    }

Problem is iam not getting controls in aspx page in SaveInfo.Can anybody help to access controls in form inside saveinfo?


Static page methods cannot get the page's control tree. (They don't receive ViewState)

You will need to use an UpdatePanel.

You can make an asp:Button inside a <div style="display:none> with a regular Click event, make an UpdatePanel triggered by the button, and use Javascript to simulate a click of the button.

Alternatively, you could send the values of the controls that you need as parameters to your page method in Javascript. This will be more efficient than using an UpdatePanel.


You can't.

Your WebMethod is static, meaning it exists once, for all instances of your page class. It has no notion of any individual instance of your Page.

If you need to post your page back, you'll need to actually use postbacks, and not web service calls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜