想要在表单提交后立即执行一些客户端脚本 [英] Want to execute some client script immediately after form has submitted

查看:89
本文介绍了想要在表单提交后立即执行一些客户端脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..

我正在使用一个aspx页面,当点击一个链接按钮时,它将返回到其他页面(新页面将在新标签页中打开)。



i想要在页面提交当前请求之后和用户发送另一个请求之前执行一个小的javascript函数。







有人可以帮我吗



提前谢谢

hi..
im using an aspx page which will get postback to some other page(the new page will be opened in a new tab) when clicked on a link button.

i want to execute a small javascript function after page has submitted for the current request and before user sends another request.



Could someone help me

thanks in advance

推荐答案

你可以使用OnClientClick =属性获取链接按钮



像这样:



you can use OnClientClick="" attribute for link button

like this :

<asp:LinkButton ID="lbltest"    OnClientClick="alert('test');"  OnClick="linkBtn_Click"   runat="server" >


谢谢Rana Zarour ..!



我想你没得到我的问题很清楚..!



您将在提交页面之前执行。

但我想在页面后执行代码提交
Thanks Rana Zarour..!

I think You didnt get my problem clearly..!

your will be executed before the page is submitted.
but i want to execute the code after the page has submitted


hi


从后面的代码调用javascript





hi
call the javascript from code behind


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)


             // your code..

              Dim script As String = "alert('something')"
    If Not Page.ClientScript.IsStartUpScriptRegistered(Me.GetType(), "alertscript") Then
        Page.ClientScript.RegisterStartUpScript(Me.GetType(), "alertscript", script, True)

    End If
    End Sub





使用javascript:





using javascript:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <script type="text/javascript">

        var somefuntion = function () {
            alert('some scripting');
            document.getElementById('<%= btnHidden.ClientID %>').click();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:LinkButton ID="Button2" runat="server" OnClientClick="somefuntion()" Text="Button"

        PostBackUrl="~/Gridpage.aspx" />
    <asp:Button ID="btnHidden" runat="server" Style="display: none" Text="" OnClick="btnHidden_Click" />
    </form>
</body>
</html>


这篇关于想要在表单提交后立即执行一些客户端脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆