Asp.Net UpdatePanel无法正常工作

时间:2015-09-21 12:49:21

标签: asp.net vb.net updatepanel

您好我在使用更新面板在我的网页中正常运行时遇到了一些问题。我有一个文本框,用户输入一个id然后点击返回键以填充另一个带有地址的文本框。该页面在Chrome和FireFox上工作得非常好,但是在IE和Safari中,每次按下返回键时,都会在音量上添加一个新行。我试图通过使用更新面板仅更新id和地址文本框来解决此问题,但无论新行添加到卷中的是什么。

任何人都知道我的错误在哪里

enter image description here

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<table border="1" width="960px">  
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
 <asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
 <Triggers>
       <asp:AsyncPostBackTrigger controlid="Button1" eventname="Click" />
 </Triggers>
 <ContentTemplate>
  <tr>
    <td rowspan="1">Customer Account Code</td>    
         <td><asp:TextBox ID="txtCustomerCode" runat="server" placeholder="Enter code press return" /></td>
         <asp:Button ID="Button1" runat="server" onclick="Button1_KeyDown"  Style="display: none" />    

    <td rowspan="1" colspan="1"><asp:DropDownList ID="DropDownListSelectAddress" class="DropDownListSelectAddress" runat="server"  AutoPostBack = "true" OnSelectedIndexChanged = "SelectedIndexChanged"></asp:DropDownList></td>
  </tr>
  <tr>
    <td>Customer Account</td>
    <td colspan="1" width="300px"><asp:TextBox ID="txtCustomer" width="300px" runat="server" ></asp:TextBox></td>
    <td rowspan="4" colspan="1"><asp:TextBox ID="selectedAddressTextBox" class="selectedAddressTextBoxNQ"  Width="430px" TextMode="multiline" runat="server"></asp:TextBox></td>
  </tr>
  <tr>
        <td colspan="1">Customer Part Number/Description</td>
        <td colspan="2"><asp:TextBox ID="txtCustomerPartNumber" runat="server"></asp:TextBox></td>
  </tr>
  <tr>
        <td colspan="1">Sales Person</td>
        <td colspan="1"><asp:TextBox ID="tbSalesPerson" runat="server"></asp:TextBox></td>
  </tr>
  <tr>
        <td colspan="1">End Customer</td>
        <td colspan="1"><asp:DropDownList ID="dbEndCustomer" Width="100px" runat="server" OnSelectedIndexChanged="FillSelectedAddressTextBox"></asp:DropDownList></td>
  </tr>
  </ContentTemplate>
</asp:UpdatePanel>


  <tr>
        <td colspan="1" valign="Top">Annual Volume</td>
        <td colspan="2"><asp:Table width="300" ID="Table1" runat="server"  ></asp:Table>            
                        <asp:Button ID="btnAddVolume" class="btnAddVolume" runat="server" Text="Add Volume"/>                        
                        <asp:Button ID="btnRemoveVolume" class="btnRemoveVolume" runat="server" Text="Remove Volume"/></td>
  </tr>

Sub生成卷表。

Protected Sub GenerateTable(noOfRows As Integer)
    Dim table As Table
    Dim row As TableRow
    Dim cell As TableCell
    Dim tb As TextBox
    Dim lbl As Label
    table = Table1
    table.ID = "Table1"

    'Page.Form.Controls.Add(table)
    For i As Integer = 1 To noOfRows Step 1
        row = New TableRow()
        For j As Integer = 0 To 1 Step 1
            cell = New TableCell()
            If j = 1 Then
                tb = New TextBox()
                tb.ID = "TextBoxRow_" & i & "Col_" & j
                cell.Controls.Add(tb)
            ElseIf j = 0 Then
                lbl = New Label()
                lbl.ID = "Label" & i
                lbl.Text = "Volume " & i
                cell.Controls.Add(lbl)
            End If


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

    'SetPreviousTableData(noOfRows)
    ViewState("RowsCount") = noOfRows
    Session("RowsCount") = noOfRows

End Sub

初始化子

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    DropDownListSelectAddress.Visible = False
    Dim menu As Menu = CType(Me.Master.FindControl("menu2"), WebControls.Menu)
    menu.Items(4).Text = "logout"
    If IsPostBack Then
        Dim table As Table
        Dim rowCount As Integer
        Dim messagestring
        messagestring = getPostBackControlName()
        ' MsgBox(messagestring)
        noOfRows = Session("RowsCount")
        If messagestring = "btnAddVolume" Then
            noOfRows = noOfRows + 1
        End If
        If messagestring = "btnRemoveVolume" Then
            noOfRows = noOfRows - 1
        End If
        If noOfRows = 0 Then
            ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('Must have at least one volume');", True)
            noOfRows = noOfRows + 1
        End If
        GenerateTable(noOfRows)
        table = Table1
        rowCount = table.Rows.Count
        'Dim volume1 As TextBox
        'volume1 = table.Rows(0).Cells(1).FindControl("TextBoxRow_" & 1 & "Col_" & 1)
        ' volume1 = Page.FindControl("TextBoxRow_1Col_1")
    End If
End Sub

Page_Load Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
        dbColour.AutoPostBack = True
        dbCurrency.AutoPostBack = True
        dbCutters.AutoPostBack = True
        dbEndCustomer.AutoPostBack = True
        dbManuSite.AutoPostBack = True
        dbMaterial.AutoPostBack = True
        fillDropDowns()
        GenerateTable(noOfRows)
        selectedAddressTextBox.Text = ""
    Else
        ' Dim table As Table
        '  table = Table1
        '  Dim volume1 As TextBox
        '  volume1 = table.Rows(0).Cells(1).FindControl("TextBoxRow_" & 1 & "Col_" & 1)
        '  MsgBox(volume1.Text)
    End If


    Dim menu As Menu = CType(Me.Master.FindControl("menu2"), WebControls.Menu)
    menu.Items(4).Text = "logout"

    If menu.Items(4).Selected Then
        Session.Clear()
        FormsAuthentication.SignOut()
        Response.Redirect("Default.aspx")
    End If

End Sub

0 个答案:

没有答案
相关问题