Tuan Nguyen
Tuan Nguyen

Reputation: 3

Call Javascript function and pass value from C#

in HTML:

<script type="text/javascript">
function removeIndustry(item)
    {
        confirm(item);
    }
</script>

in C#:

protected void Page_Load(object sender, EventArgs e)
{
    Label1.Text = "<a href='javascript:removeIndustry('IndustryNameHere')'><i class='icon-remove'></i></a>Click";
}

The code is not working if I put any strings like 'IndustryNameHere' in that function. Without any values, it is working fine. Anyone please help me fix this error. Thanks a lot.

Upvotes: 0

Views: 64

Answers (1)

Manwal
Manwal

Reputation: 23846

Try to escape quotes with \:

protected void Page_Load(object sender, EventArgs e)
{
    Label1.Text = "<a href=\"javascript:removeIndustry('IndustryNameHere')\"><i class='icon-remove'></i></a>Click";
}

Upvotes: 2

Related Questions