方法1:
<script>
function submitForm( theForm ){
theForm.action = 'http://www.sohu.com';
//theForm.submit();
return true;
}
</script>
<form id="form1" name="form1" runat="server" method="post" action="" target="_blank" οnsubmit="return submitForm(this)">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:submitForm" οnclick="LinkButton1_Click" />
......
<script type="text/javascript">
if(allowRun!=undefined && allowRun==true)
{
submintForm(document.forms['form1']);
}
</script>
然后在你的服务端LinkButton1_Click处理函数中这么写:
LinkButton1_Click(object sender, EventArgs e)
{
//......
Responsw.Write("<script type='text/javascript'> var allowRun=true; </script>");
}
方法2
ClientScript.RegisterStartupScript(ClientScript.GetType(),
"myscript", "<script>submintForm(document.forms['form1']);</script>");