在 html select 上设置 selected 值而不使用 runat=server

Set selected value on html select without using runat=server

我正在使用 this iconpicker 插件让用户选择一个图标并将其保存在数据库中。之后,当用户返回页面时,我想将保存的图标加载为下拉列表的 selected 值。 我不能在 select 上使用 runat=server,因为如果我这样做,插件将停止工作。 Select代码:

<select id="ddlIcona" name="ddlIcona" class="myselect">
    <option value="">No icon</option>
    <option>icon-user</option>
    <option>icon-search</option>
    <option>icon-heart</option>
    <option>icon-star</option>
    <option>icon-users</option>
    <option>icon-camera</option>
</select>

我懒得使用隐藏字段向服务器传递值。 我怎样才能做到这一点?谢谢

Aspnet 重命名控件的 ID,通常在使用母版页或 Repeater、Gridview 等控件时

所以控件看起来像这样:

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

在 HTML 中可以有一个 ID PlaceHolder1_Label1

因此 ClientID 通常用于确保在 javascript 中引用了正确的 ID。

<script>
    alert('<%= Label1.ClientID %>');
</script>