Call jQuery function from ASP.NET code behind C#

I have the following jquery function

> <script type="text/javascript">
> 
>     $(document).ready(function() {
> 
>         $('#callGrowel').click(function() {
>             $.growlUI('Email Received', 'from Joe Bloggs');
>         });
>     });
> 
> </script>

and in my aspx page I have a div

<div id="callGrowel" >Run Growe l</div>

but I need a way of calling the growlUI jquery function from my code behind file in C# rather than clicking on a div in the UI.

Is this possible??

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I’ve use following way and for me work 100% properly:

the first i create a function and write my jquery function in to the function in the my page:

<script>
function myFunction(params) {
    $.my_jquery(params...)
    ......
}

then i used this code in event handler of my control(for example click a button) who my control is inside a update panel:

protected void myButton(object sender, EventArgs e)
{
    .....
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "<script type='text/javascript'>myFunction(params...);</script>", false);
}

successful

Method 2

This doesn’t make sense really. Your C# code runs on the server to generate an HTML file which is passed to the client and translated there. jQuery can only operate on the HTML n the client side.

Is what you’re trying to do not achieved by replacing

     $('#callGrowel').click(function() {
         $.growlUI('Email Received', 'from Joe Bloggs');
     });

with

     $.growlUI('Email Received', 'from Joe Bloggs');

?


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x