asp.net - Serve Tag not well formed when using EVAL() in OnClientClick event -
i'm trying create onclick event so
onclientclick="document.queryselector('[kpi="31"]').value = '';return false;"
the kpi= value has data bound, use code so
onclientclick="<%# document.queryselector('[kpi=eval("kpi_id")]').value = '';return false; %>"
but error saying server code not defined. please..
if datasource collection of objects , requesting property called kpi_id can avoid using eval , use item or container.dataitem.
easiest way me show container.dataitem, since don't know kind of control using bind to. container.dataitem should object, need cast datatype
onclientclick="document.queryselector('[kpi=<%# ((yourdatatype)container.dataitem).kpi_id %>)]').value = '';return false;"
if use repeater in .net 4.5 can set itemtype repeater datatype can replace ((yourdatatype)container.dataitem) item:
onclientclick="document.queryselector('[kpi=<%# item.kpi_id %>)]').value = '';return false;"
if not using property object , kpi_id string use actual value, e.g. if it's in datarow, have avoid using " in whole string, without letting compiler know it's not end of attribute. can using ' indicate start , end of attribute , use string.format single quote ' in javascript part of text , compiler knows it's not end of attribute:
onclientclick='<%# string.format("document.queryselector('[kpi={0}]').value = ''; return false;", eval("kpi_id")) %>'
update: support the additional double quote can do:
onclientclick='<%# string.format("document.queryselector('[kpi=\"{0}\"]').value = ''; return false;", eval("kpi_id")) %>'
you can replace eval("kpi_id") item.kpi_id or ((yourdatatype)container.dataitem).kpi_id if wanna avoid using eval.
Comments
Post a Comment