从后面的代码创建单选按钮但是有一个onclick?

时间:2015-09-15 15:20:58

标签: javascript c# jquery asp.net

前端有一张桌子......

<table>
<tr>
<td style="padding-right:8px">
<input id="mmapMS" type="radio" name="Layers" value="mmapMS" onclick="addLayer()" style="display:none"/>
<label class="Layer-cc mMS" for="mMS" data-tip="mMS"></label>
</td>
</tr>
</table>

需要更改单选按钮从后端运行...到目前为止一切都很好(下面)但是当我点击单选按钮时我无法找到如何调用js函数?... onclick =& #34; addLayer()&#34;任何想法......谢谢

                TableRow row = new TableRow();
                TableCell cell = new TableCell();

                HtmlInputRadioButton btn = new HtmlInputRadioButton();
                btn.ID = mapGenieImage;
                btn.Value = mapGenieImage;
                btn.Visible = false;
                cell.Controls.Add(btn);

                Label lb = new Label();   
                lb.CssClass = "Layer-cc " + mapImage;
                cell.Controls.Add(lb);

                row.Cells.Add(cell);
                table.Rows.Add(row);

1 个答案:

答案 0 :(得分:0)

HtmlInputRadioButton btn = new HtmlInputRadioButton();
btn.ID = mapGenieImage;
btn.Value = mapGenieImage;
btn.Visible = false;
btn.attributes.add("onclick","addLayer()")  '<-- Add me.
cell.Controls.Add(btn);

创建控件时,添加onClick属性,调用addLayer()脚本。