在ASP.NET中点击按钮后,我需要一个JavaScript来执行其操作。我试图OnClientClick
功能,但与此事件的问题是第一OnClientClick
功能发生,然后OnServerClick
功能发生,即第一个JavaScript函数运行,然后C#代码执行,但我需要以相反的顺序首先我需要执行的C#代码,然后我不得不运行JavaScript。我在我的代码中使用AJAX.NET和ScriptManager。无论如何,scriptmanager能帮助我吗?否则如何在服务器端运行JavaScript。在服务器端运行javascript
我需要在下面的方式。
Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Add(TextBox1.Text); //for example
` here I have to run JavaScript `
}
有什么办法来实现这一点?
编辑1:
我需要一个div被onbuttonclick向下滚动(上点击添加新数据使用的DataBinder和中继器DIV)。如上所述,clientclick首先运行,但我需要在服务器操作后运行它。
JavaScript是..
<script>
var objDiv = document.getElementById("div1");
objDiv.scrollTop = objDiv.scrollHeight;
</script>
和
<div id="div1"> //css properties height 200 and width 200 overflow:auto
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
<asp:Timer ID="Timer1" runat="server" Interval="200" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater id="Repeater1" runat="server" >
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Message") %> <br />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="div2">
<asp:TextBox ID="tb_message" runat="server" Width="250px" EnableViewState="false" />
<br />
<asp:Button ID="btn_send" runat="server" Width="250px" Text="Send"
onclick="btn_send_Click" />
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn_send" EventName="click" />
</Triggers>
</asp:UpdatePanel>
是回发的AJAX回发或标准回传? –
如果可能,请提供一些代码,以便我们可以看到哪种方法适用于您的情况 – danyloid
@danyloid - 添加了代码。 –