Click here to Skip to main content
15,906,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

you can use OnClientClick="" attribute for link button

like this :

<asp:LinkButton ID="lbltest"    OnClientClick="alert('test');"  OnClick="linkBtn_Click"   runat="server" >
 
Share this answer
 
Comments
Tuduru Sai Krishna 26-Dec-13 2:56am    
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
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
 
Share this answer
 
Comments
Rana Zarour 26-Dec-13 3:10am    
if you are redirect to another page you can add your script on page load event or if in the same page you can add script on the same page page_load event after check if form was submit

am not sure if i answered your question if there is something not clear would you please add your code so i can help you ?
Tuduru Sai Krishna 26-Dec-13 3:20am    
I will explain my problem step by step.


1. my page has a linkbutton that has postbackurl property to another page.(the new page will be opened in a new tab and the current page will still available for the user).

2.as the current page will be available to the user, he/she might send another request to the server before first request has been processed and delivered (which is not desired).

so i want to execute some client script immidiately after the page has submitted to the server.

plz inform me if u have not get it yet..! :)
hi
call the javascript from code behind


VB
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


using javascript:

XML
<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>
 
Share this answer
 
v3
Comments
Tuduru Sai Krishna 26-Dec-13 4:18am    
Hi karthik mahalingam01...!

Thanks For Responding..
I will explain my problem step by step.


1. my page has a linkbutton that has postbackurl property to another page.(the new page will be opened in a new tab and the current page will still available for the user).

2.as the current page will be available to the user, he/she might send another request to the server before first request has been processed and delivered (which is not desired).

so i want to execute some client script immidiately after the page has submitted to the server.(Inother words, execute some client script before the next request)

plz inform me if u have not get it yet..! :)
Karthik_Mahalingam 26-Dec-13 4:31am    
if you use a valid postbackurl , it wont do post back to the current page ... it will open the url in current page or another..
Tuduru Sai Krishna 26-Dec-13 4:38am    
yes karthik mahalingam01...!

You are absolutely true..! i have used wrong terminology..!

but how can i solve my problem
Karthik_Mahalingam 26-Dec-13 4:44am    
you can use javascript..
Tuduru Sai Krishna 26-Dec-13 4:51am    
can u please explain...!

or write a piece of code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900