简体   繁体   中英

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.

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";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM