在不使用runat = server的情况下在html选择上设置所选值

时间:2018-02-13 14:17:43

标签: javascript jquery asp.net html-select

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

<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>

我不想使用隐藏字段将值传递给服务器。 我怎样才能做到这一点?谢谢

1 个答案:

答案 0 :(得分:1)

Aspnet重命名控件的ID,通常在使用Master Pages或控件(如Repeater,Gridview等)时。

所以控件看起来像这样:

Public Sub SOExample()
    Dim html     As Object 'To store the HTML content
    Dim Elements As Object 'To store the anchor collection
    Dim Element  As Object 'To iterate the anchor collection
    Set html = CreateObject("htmlFile")

    With CreateObject("MSXML2.XMLHTTP")
        'Navigate to the source of the iFrame, it's another page
        'View the source for the iframe. Alternatively -
        'you could navigate to this page and use IE to scrape it
        .Open "GET", "https://stocks.thehindubusinessline.com/Companydetails.aspx?&cocode=INE117A01022"
        .send ""

        'See if the request was ok, exit it there was an error
        If Not .Status = 200 Then Exit Sub

        'Assign the page's HTML to an HTML object
        html.body.InnerHTML = .responseText
        Set Elements = html.body.document.getElementByID("hmstockchart_CompanyNews1_updateGLVV")
        Set Elements = Elements.getElementsByTagName("a")

        For Each Element In Elements
            'Print out the data to the Immediate window
            Debug.Print Element.InnerText
        Next

    End With
End Sub

HTML中可以包含ABB India Limited - AGM/Book Closure Board of ABB India recommends final dividend ABB India to convene AGM ABB India to pay dividend ABB India Limited - Outcome of Board Meeting More ? 的ID。

因此<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 通常用于确保在javascript中引用正确的ID。

PlaceHolder1_Label1