Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to call a javascript function on button click. On button click data binds to gridview and then this function is called.

I am trying to call function like:
ClientScript.RegisterClientScriptBlock(this.GetType(), "tmp", "CreateClickableLinks();", true);


And function is present in aspx file.
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/Validation.js"> </script>
    <script type="text/javascript" src="../Scripts/progress.js"></script>
    <script type="text/javascript">

        function CreateClickableLinks() {
            alert($("#<%=gvOpenProblems.ClientID %>").html());
        }    
    </script>


When I run code I get error as Object expected : CreateClickableLinks

Is there anything wrong in the way I call function or there is something wrong with function itself?
Posted

The RegisterClientScriptBlock[^] method adds a script block to the top of the rendered page. It might be that when the call is made the definition is not yet added.

Instead try: ClientScriptManager.RegisterStartupScript Method[^]

See if it helps.
 
Share this answer
 
hi
ClientScript.RegisterClientScriptBlock(this.GetType(), "tmp", "alert($("#<%=gvOpenProblems.ClientID %>");", true);



try it... its working... you code is not working bcoz from code behind file it can't be found the function write in script tag due to event args missing.
So try above code means just write your javascript inside the code behind clientscript




regards,
saurabh
 
Share this answer
 
Comments
Sandeep Mewara 27-Apr-12 3:29am    
It's a profession website. Please avoid text speak - words like bcoz.

What do you mean by 'event args' missing? Writing JS in code behind too will work but what if my implementation of JS is too large?
Try to use this statement.. it will resolve your issue.

C#
ClientScript.RegisterClientScriptBlock(this.GetType(), "tmp","CreateClickableLinks();", false);


************
Happy Coding.. :)
 
Share this answer
 
v2

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