Javascript 调用C codebehind函数,当我单击按钮时,div将显示
当用户单击按钮1时,如何调用按钮1\u Click 试试看Javascript 调用C codebehind函数,当我单击按钮时,div将显示,javascript,c#,jquery,html,asp.net,Javascript,C#,Jquery,Html,Asp.net,当用户单击按钮1时,如何调用按钮1\u Click 试试看 使用RegisterClientScriptBlock而不是RegisterStartupScript方法。但目前没有。您目前拥有的有点愚蠢。它将回发到服务器,然后服务器将处理服务器端单击事件,并将javascript发送到浏览器,当响应返回时,浏览器将运行javascript。您可能需要类似OnClientClick=showdivslow这样的东西,以避免请求/响应往返。请看,如果一致意见为否,则不应该! protected voi
使用RegisterClientScriptBlock而不是RegisterStartupScript方法。但目前没有。您目前拥有的有点愚蠢。它将回发到服务器,然后服务器将处理服务器端单击事件,并将javascript发送到浏览器,当响应返回时,浏览器将运行javascript。您可能需要类似OnClientClick=showdivslow这样的东西,以避免请求/响应往返。请看,如果一致意见为否,则不应该!
protected void Button1_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "id", "show(showdivslowly)", true);
}
<!-- language: lang-html -->
<div id="showdivslowly" runat="server" style="width: 500px; height: 200px; background-color: Blue; display: none">Welcome</div>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
protected void Button1_Click(object sender, EventArgs e)
{
string script = "show(showdivslowly);";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Show", script, true);
}