2011-12-18 49 views
-1

我有一個標準的按鈕應該調用一個方法,但它只是拒絕工作,我不明白爲什麼。按鈕拒絕工作

ASP代碼:

<asp:FileUpload ID="FileUpload1" runat="server" /> 
     <asp:Button 
      ID="UploadButton" runat="server" onclick="UploadButton_Click" Text="Change Logo" /> 

後面的代碼:

protected void UploadButton_Click(object sender, EventArgs e) 
     { 
      PasswordLabel.Visible = true; 
      PasswordLabel.Text = "TEST Before"; 
      Image_Inserting(this); 
      PasswordLabel.Text = "TEST After"; 

     } 

我剛添加的文本框方法來測試它,但它似乎並沒有被回發(甚至當我刪除I​​mage_Inserting通話)。所有其他按鈕都可以正常工作,所以我不知道爲什麼這個按鈕不起作用。

編輯:向底部

<%@ Page Title="" Language="C#" MasterPageFile="~/Standardmaster.Master" AutoEventWireup="true" CodeBehind="VendorAccount.aspx.cs" Inherits="PetShopParadise.Vendor_Pages.VendorAccount" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
    <style type="text/css"> 
     .style10 
     { 
      color: #FF0000; 
     } 
    </style> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="server"> 

    <h2>Account Details</h2> 

    <div id="RegistrationDiv"> 
     <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1"> 
      <EditItemTemplate> 
       Name: 
       <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' /> 
       <br /> 
       Address: 
       <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' /> 
       <br /> 
       Phone_Number: 
       <asp:TextBox ID="Phone_NumberTextBox" runat="server" 
        Text='<%# Bind("Phone_Number") %>' /> 
       <br /> 
       <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
        CommandName="Update" Text="Update" /> 
       &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
        CausesValidation="False" CommandName="Cancel" Text="Cancel" /> 
      </EditItemTemplate> 
      <InsertItemTemplate> 
       Name: 
       <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' /> 
       <br /> 
       Address: 
       <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' /> 
       <br /> 
       Phone_Number: 
       <asp:TextBox ID="Phone_NumberTextBox" runat="server" 
        Text='<%# Bind("Phone_Number") %>' /> 
       <br /> 
       <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
        CommandName="Insert" Text="Insert" /> 
       &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
        CausesValidation="False" CommandName="Cancel" Text="Cancel" /> 
      </InsertItemTemplate> 
      <ItemTemplate> 
       Name: 
       <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' /> 
       <br /> 
       Address: 
       <asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' /> 
       <br /> 
       Phone Number: 
       <asp:Label ID="Phone_NumberLabel" runat="server" 
        Text='<%# Bind("Phone_Number") %>' /> 
       <br /> 
        <asp:Button ID="Button3" runat="server" Text="Edit Details" CommandName="Edit" /> 
        <br /> 

      </ItemTemplate> 
     </asp:FormView> 
     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="<%$ ConnectionStrings:PetShopParadiseConnectionString %>" 
      SelectCommand="SELECT [Name], [Address], [Phone_Number] FROM [Vendors] WHERE ([VendorID] = @VendorID)"> 
      <SelectParameters> 
       <asp:SessionParameter Name="VendorID" SessionField="ID" Type="Decimal" /> 
      </SelectParameters> 
     </asp:SqlDataSource> 
        <br /> 
     <asp:Table ID="Table1" runat="server" style="text-align:left;"> 
      <asp:TableRow ID="TableRow4" runat="server"> 
       <asp:TableCell ID="TableCell7" runat="server">Password</asp:TableCell><asp:TableCell ID="TableCell8" runat="server"> 
        <asp:TextBox ID="PasswordBox" TextMode="Password" runat="server"></asp:TextBox> 
        <asp:RequiredFieldValidator 
         id="RequiredFieldValidator5" 
         runat="server" 
         ControlToValidate="PasswordBox" 
         Display="None" 
         Forecolor="Red" 
         ErrorMessage="Please enter a password." /> 
         </asp:TableCell></asp:TableRow><asp:TableRow ID="TableRow5" runat="server"> 
       <asp:TableCell ID="TableCell9" runat="server">Re-Enter Password</asp:TableCell><asp:TableCell ID="TableCell10" runat="server"> 
        <asp:TextBox ID="PasswordCheckBox" TextMode="Password" runat="server"></asp:TextBox> 
        <asp:RequiredFieldValidator 
         id="RequiredFieldValidator6" 
         runat="server" 
         ControlToValidate="PasswordCheckBox" 
         Display="None" 
         Forecolor="Red" 
         ErrorMessage="Please re-enter your password." /> 
        </asp:TableCell></asp:TableRow></asp:Table><asp:Label 
      ID="PasswordLabel" runat="server" Text="Password" CssClass="style10"></asp:Label><br /> 
        <asp:Button ID="PasswordButton" 
      runat="server" Text="Update Password" onclick="PasswordButton_Click" /><br /> 


      <asp:SqlDataSource 
      ID="SqlDataSource2" runat="server" 
      ConnectionString="<%$ ConnectionStrings:PetShopParadiseConnectionString %>" 
      onselecting="SqlDataSource2_Selecting" SelectCommand="SELECT * FROM Vendors" 
      UpdateCommand="UPDATE [Vendors] SET [Password][email protected] WHERE ([VendorID] = @VendorID)" OnUpdating="Parameters_Updating"> 
      <UpdateParameters> 
      <asp:Parameter Name="Password" /> 
      <asp:SessionParameter name="VendorID" sessionfield="ID" /> 
      </UpdateParameters> 
      </asp:SqlDataSource> 

      <br /><asp:FileUpload ID="FileUpload1" runat="server" /> 
     <asp:Button 
      ID="UploadButton" runat="server" onclick="UploadButton_Click" Text="Change Logo" /></div></asp:Content> 



        <asp:Content ID="Content3" ContentPlaceHolderID="bannerContent" runat="server"> 
</asp:Content> 
+0

你在頁面上是否有一些JS: – 2011-12-18 12:25:57

+0

嘗試使用調試器而不是使用TextBox輸出。如果您在上述方法中放置斷點,或者Debug.Write(「...」)是否在Visual Studio的輸出窗口中看到任何內容? – 2011-12-18 12:27:02

+0

PasswordLabel是什麼類型?它是密碼文本框?請更新。 – 2011-12-18 12:27:12

回答

1

我的猜測是,它是造成其他(可能是隱藏的)驗證運行。請務必設置原因驗證虛假

+0

因爲它沒有註冊點擊,你可以假設JS阻塞。 – naspinski 2011-12-18 13:08:49

+0

這樣做,非常感謝。我可以問一個按鈕如何隱藏驗證? (仍然是新的ASP,仍然找出扭曲) – Matt 2011-12-18 13:11:03

+0

Asp.Net WebForms是一個奇怪的怪物...有時可以隱藏的意見,仍然驗證,因爲整個頁面在一種形式。例如,表單仍包含上面的所有更新標記,因此表單中的按鈕將驗證該表單,除非您明確表示不要。我對你的愛好,去Asp.Net MVC,永不回頭:)你的生活會更容易(和更高的薪水...)。 – naspinski 2011-12-18 13:14:55

0

報價整體PAGE-按鈕代碼: *我剛添加的文本框方法*

我想我們試圖更新密碼的textBox你不能。

只有:

PasswordLabel .Attributes["value"] = "aaa"; 
+0

這只是一個正常的標籤,我使用調試器來查看它是否真的進入了方法,但它似乎沒有註冊鼠標點擊並調用方法。 – Matt 2011-12-18 12:35:50

+0

你可以上傳整個頁面指令的頂部線? – 2011-12-18 12:37:23

+0

好的,感謝您的幫助。 – Matt 2011-12-18 12:44:20