-2

I have the function below which needs to be called from C#

$('.image-cropper').each(linkUp);

Can anyone explain how it could be done. I tried using the below code

    String csname1 = "PopupScript";
    Type cstype = this.GetType();
    ClientScriptManager cs = Page.ClientScript;
    StringBuilder cstext2 = new StringBuilder();
    cstext2.Append("<script type=\"text/javascript\"> $('.image-cropper').each(linkUp); </");
    cstext2.Append("script>");
    cs.RegisterClientScriptBlock(cstype, csname1, cstext2.ToString(), false);

but it did not work.

7
  • @rick Schott It did not call the function Commented Oct 15, 2011 at 3:04
  • 5
    You probably need to wrap your JS in $(document).ready() so the DOM's loaded when you try to select elements Commented Oct 15, 2011 at 3:06
  • What browser are you using ? does it have a development console that can show you errors ? I ask, as it maybe that your emitted Javascript is executing before jQuery is added to the page. Commented Oct 15, 2011 at 3:06
  • 1
    This is a duplicate of many questions, but most recently stackoverflow.com/questions/7775284/… as answered by rick schott Commented Oct 15, 2011 at 3:32
  • 1
    Why is your question tagged with asp.net-mvc? I sincerely hope you are not using anything like this in an ASP.NET MVC application. Commented Oct 15, 2011 at 9:39

1 Answer 1

0

You should really be calling your code inside the jQuery ready function ie:

$(function() {
    $('.image-cropper').each(linkUp);
});

The likely reason your code wasn't working was that the image-cropper elements weren't in the DOM when your code was run.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.