Webpart Postback generation inside c# code
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!!!
}
}
精彩评论