Hi i have a jquery function which executes when a button is clicked, i also need to execute this function from my code behind based on whether an Item has a comment attached to it. Here is the jquery
//Comments Slide
$('.commentsnr').live("click", function () {
// up to parent li
$li = $(this).closest('li');
$li.find("#commentload").slideToggle(300);
});
How do i call this from my code behind, thanks alot
You can do this, but it will only be executed when the page is delivered or you receive a Postback.
See ClientScriptManager.RegisterStartupScript for documentation.
string jquery = "$('.commentsnr').live(\"click\", function () {$li = $(this).closest('li');$li.find(\"#commentload\").slideToggle(300);});"
ClientScript.RegisterStartupScript(typeof(Page), "a key",
"<script type=\"text/javascript\">"+ jquery +"</script>"
);
try this
Page.ClientScript.RegisterStartupScript(typeof(String), btnID,"$('.commentsnr').live("click", function () {
$li = $(this).closest('li');
$li.find("#commentload").slideToggle(300);});", True);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With