English 中文(简体)
ASP. NET VB。 NET - Winforms to Web - implementing loss Focus listview control Equal for web
原标题:ASP.NET VB.NET - Winforms to Web - implementing LostFocus listview control equivalent for web

背景: 我有一个双赢论坛,即根据所提供的信息,在数据库中登记用户,自动生成随机密码和用户名称,并电子邮件用户链接,根据选定的营销公司接收申请。

Problem:

  • When the user selects the lbCarrier(s), the Bundles don t show up in the listbox b/c the lostfocus feature doesn t work for asp.net. What code can I use to auto-populate the Bundles listbox based on what is selected in lbCarrier listbox for ASP.NET.

web app screenshot

Code from default.aspx.vb:

Private Sub lbCarriers_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbCarriers.LostFocus
    Dim splt() As String
    Dim ac1 As Array
    bundles.Items.Clear()
    For Each item In lbCarriers.Items

        splt = Split(item.text, "|")
        ac1 = proxy.GetContractingBundles("test", "test", Trim(splt(0)))
        For Each Pitem In ac1
            bundles.Items.Add(Trim(splt(2)) & " | " & Pitem.FormBundleName)
        Next
    Next
End Sub

Protected Sub lbCarriers_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles lbCarriers.SelectedIndexChanged

End Sub
最佳回答

You ll need to do some client-side javascript, or add an AutoPostBack on the dropdownlist and code the OnSelectedIndexChanged event:

<asp:DropDownList AutoPostBack="true" OnSelectedIndexChanged="MethodName" ...

Also, the LostFocus event only fires on the client, not on the server, and it is a Javascript event called "Blur":

http://www.java2s.com/Code/JavaScriptReference/Javascript-Methods/blur.htm

问题回答

I would suggest you look into using jQuery. It makes client side programming much simpler. What you need to do is make an asynchronous AJAX request to the server when the focus is lost, then have the server return just the data you want to display in the list box.

这应当放在你主要网页的底层:

<script type="text/javascript">
$(document).ready(function() {
    $("#lbCarrier").onblur(function () {
        // Ask the server for the list
        $.ajax({
           type: "POST",
           url: "getlist.aspx",
           data: "option=" + $("#lbCarrier").val(),
           success: function(result) {
               // When you get the result, populate the Bundles list
               $("#lbBundles").......
           }
         });
    });
});
</script>

您需要创建第二页(目标名单.aspx),接受关于“选择”的争辩,该争辩将选定承运人的舱位归来。

I got the bundles listbox to populate w/ autopostback set to true but the bundles listbox populates as soon as you click on an lbcarrier and it doesn t allow you select more than one carrier.

你们是否对如何以背后的特点让多位当选有任何想法?

缺省法。 页: 1

            <asp:ListBox AutoPostback="true" ID="lbCarriers" runat="server" Height="86px" Width="250px">
            </asp:ListBox>

缺省法典。

Protected Sub lbCarriers_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles lbCarriers.SelectedIndexChanged

    Dim splt() As String
    Dim ac1 As Array
    bundles.Items.Clear()
    Dim item As ListItem = lbCarriers.SelectedItem
    splt = item.ToString().Split("|")
    ac1 = proxy.GetContractingBundles("test", "test", Trim(splt(0)))
    For Each Pitem In ac1
        bundles.Items.Add(Trim(splt(2)) & " | " & Pitem.FormBundleName)
    Next
End Sub




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签