开发者

Webpart Postback generation inside c# code

开发者 https://www.devze.com 2023-03-17 23:03 出处:网络
I\'m having some troubles with sharepoint webparts\' programming! I don\'t know how to make an object rise a postback when i want! I read in many place that this can be done by \"javascript\", but i c

I'm having some troubles with sharepoint webparts' programming! I don't know how to make an object rise a postback when i want! I read in many place that this can be done by "javascript", but i can't understand what they means..

Suppose I'm in this situation

void BIGenerate_Click(object sender, EventArgs e)
{
if (this.txtPassword.Text != "")
{
bla bla bla code
}
//CODE TO GENERATE POSTBACK
}

What co开发者_如何学Cde i have to put there? How can i invoke a javascript in that moment? Thank you very much!


ASP.NET creates a client side javascript to support postbacks:

function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}

Now you only have to call you postback function with some arguments:

<script language='Javascript'>
    __doPostBack('__Page', 'MyArg');
</script>

Now you have to catch the postback in your codebehide:

   if (IsPostBack)
   {
       string eventArg = Request["__EVENTARGUMENT"];
       if (eventArg == "MyArg")
       {
           // Do some stuff with my postback!!!
       }
   }
0

精彩评论

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

关注公众号