0

Please help me solve this challenge:( I have below code:

Label lblVideoAssessment = new Label();
                        lblVideoAssessment.Text = "<a href='../SitePages/Assessment.aspx?cat=" + cat + "' height='300px' width='300px' Target='_blank' cssClass='IconDisplayCss'><img src='~/_layouts/images/Assessment.png' border='none'/></a><br/>" + cat;

I want to replace above code by a dialogue box instead of opening a new page "Ässessment.aspx". I have tried like this:

lblVideoAssessment.Text = "<a cssclass='IconDisplayCss' width='300px' height='300px' onclick='javascript:OpenDialog('../SitePages/Assessment.aspx?cat='+cat+);return false;'><img border='none' src='~/_layouts/images/Assessment.png'></a>";

However it doesnot work. I think the issue is with the ''(Quotation which i have placed ) or do i need to use Page.ClientScript.RegisterStartupScript

if yes...how and where do i place it?

Please help as i have been struggling for fort night.

I had also got suggestion to use Literal Control.I have tried that as well and it does not work.

1 Answer 1

1
var strScript = "<script language=\"JavaScript\" type=\"text/javascript\">";
strScript += "alert(\"hello\")";
strScript += "</script>";
Page.ClientScript.RegisterClientScriptBlock(GetType(), "onload", strScript, false);

Good Luck!

Edit:

var script = "<script language=\"JavaScript\" type=\"text/javascript\">$('#tag').click(function () {})</script>"; Page.ClientScript.RegisterClientScriptBlock(GetType(), "ready", script , false);

Finally:

var script = "<script language=\"JavaScript\" type=\"text/javascript\">$(\".IconDisplayCss\").click(function () {OpenDialog('../SitePages/Assessment.aspx?cat='" + cat + "); });</script>" Page.ClientScript.RegisterClientScriptBlock(GetType(), "ready", script , false);
Sign up to request clarification or add additional context in comments.

3 Comments

Here the AlertBox appears in on Pageload but i want on anchor tag clickevent, the javascript method should occur how to do...?if you can see the code above from question.
var script = "$('#tag').click(function () {})"; Page.ClientScript.RegisterClientScriptBlock(GetType(), "ready", script , false);
var script = "<script language=\"JavaScript\" type=\"text/javascript\">$(\".IconDisplayCss\").click(function () {OpenDialog('../SitePages/Assessment.aspx?cat='" + cat + "); });</script>" Page.ClientScript.RegisterClientScriptBlock(GetType(), "ready", script , false);

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.