2012-07-19 2 views
0

현재 내 프로젝트에서 asp : formview를 사용하고 있습니다.asp : FormView ItemUpdating 이벤트가 실행되지 않음

<asp:FormView ID="formViewGalleryEdit" runat="server" DefaultMode="Edit" 
      RenderOuterTable="False" DataKeyNames="GalleryID" 
      onitemupdating="formViewGalleryEdit_ItemUpdating"> 
      <EditItemTemplate> 
       <div class="field-group"> 
        <label for="textBoxVendorName">Gallery Heading:</label> 
        <div class="field"> 
         <asp:TextBox runat="server" ID="textBoxGalleryHeading" Width="90%" 
          Text='<%# Eval("GalleryHeading").ToString() %>' /> 
        </div> 
       </div> 
       <div class="field-group">  
        <label for="textBoxDescription">Gallery Description:</label> 
        <div class="field"> 
         <asp:TextBox runat="server" ID="textBoxDescription" Text='<%# Eval("GalleryDescription") %>' 
          Width="90%" Columns="50" 
          Rows="7" TextMode="MultiLine" /> 
        </div>  
       </div> 
       <div class="field-group inlineField"> 
        <label for="myfile">Gallery Image:</label> 
        <div class="field"> 
         <asp:FileUpload ID="imageFileUpload" runat="server" /> 
        </div> 
       </div> 
       <br /> 
       <div class="field-group inlineField"> 
        <div class="field"> 
         <img src='/images/gallery/<%# Eval("GalleryImage") %>' alt='<%# Eval("GalleryImage") %>' /> 
        </div> 
       </div> 
       <div class="field-group">  
        <label for="textBoxDescription">Gallery Button Text:</label> 
        <div class="field"> 
         <asp:TextBox runat="server" ID="textBoxButtonText" Text='<%# Eval("GalleryButtonText") %>' 
          Width="90%" /> 
        </div>  
       </div> 
       <div class="field-group">  
        <label for="textBoxDescription">Gallery Button URL:</label> 
        <div class="field"> 
         <asp:TextBox runat="server" ID="textBoxGalleryUrl" Text='<%# Eval("GalleryButtonUrl") %>' Width="90%" /> 
        </div>  
       </div> 
       <br /> 
       <div class="field-group">  
        <div class="actions"> 
         <asp:Button ID="buttonUpdate" runat="server" CausesValidation="True" CommandArgument='<%# Eval("GalleryId") %>' 
          Width="60" CommandName="Update" Text="Update" /> 
         <asp:Button ID="buttonCancel" runat="server" CausesValidation="False" Width="60" 
          CommandName="Cancel" Text="Cancel" /> 
        </div> <!-- .actions --> 
       </div> 
      </EditItemTemplate> 
     </asp:FormView> 

이제이 파일의 코드 숨김에서 다음과 같이 처리합니다.

protected void formViewGalleryEdit_ItemUpdating(object sender, FormViewUpdateEventArgs e) 
{ 
    try 
    { 
     string galleryId = e.CommandArgument.ToString(); 
     string galleryHeading = Server.HtmlEncode(((TextBox)formViewGalleryEdit.FindControl("textBoxGalleryHeading")).Text); 
     string galleryDescription = ((TextBox)formViewGalleryEdit.FindControl("textBoxDescription")).Text; 

     FileUpload control = (FileUpload)formViewGalleryEdit.FindControl("imageFileUpload"); 
     string galleryImage = control.FileName; 
     string location = Server.MapPath("~/images/gallery/") + galleryImage; 
     control.SaveAs(location); 

     string galleryButtonText = ((TextBox)formViewGalleryEdit.FindControl("textBoxButtonText")).Text; 
     string galleryUrl = ((TextBox)formViewGalleryEdit.FindControl("textBoxGalleryUrl")).Text; 

     bool status = GalleryManager.UpdateGallery(galleryId, galleryHeading, galleryDescription, galleryImage, 
                galleryButtonText, galleryUrl); 
     if (status) 
     { 
      literalSucess.Text = "Item Updated Successfully"; 
      panelScucess.Visible = true; 
     } 
    } 
    catch (Exception ex) 
    { 
     literalError.Text = ex.Message; 
     panelError.Visible = true; 
    } 

} 

나는 또한 중단 점을 삽입했지만 이벤트를 발생시키지 않습니다. 내가 뭘 잘못하고 있니? 감사의 답변 전체 대답

답변

0

나는 바보 같이 들리 겠지만 다음 코드를 사용하여 문제를 해결합니다.

if(!Page.IsPostBack()) 
{ 
    // code goes here 
} 
+0

당신이 어디에 두 었는지 말하지 않기 때문에 투표가 중단되었습니다. 쓸만한 대답이 아닙니다. 나는 같은 문제로 여기에 있는데 내 문제를 해결하기 위해 당신의 대답을 사용할 수 없습니다. 감사. – toddmo

2

당신은 모든 것을 99 % 가지고 있습니다. the MSDN example에서 볼 수 있듯이 Button 컨트롤을 LinkButton 컨트롤로 변경하기 만하면됩니다.

<div class="actions"> 
    <asp:LinkButton ID="buttonUpdate" runat="server" CausesValidation="True" CommandArgument='<%# Eval("GalleryId") %>' 
         Width="60" CommandName="Update" Text="Update" /> 
    <asp:LinkButton ID="buttonCancel" runat="server" CausesValidation="False" Width="60" 
         CommandName="Cancel" Text="Cancel" /> 
</div> 
+0

링크 버튼 및 명령 버튼, 이전에 하나의 변화가 있었다 모두 내가 코드를 시도했을 때 –

+0

작동 같은 페이지가 보인다는 같은 코드는'와 LinkButton' 아니라 함께 일 정상적인 '버튼'. 당신은 당신의 솔루션을 정상적인 'Button'으로 작업하게 만들었습니까? 그렇지 않다면, 그리고 그것이 당신이 필요로하는 것입니다, 나는 이것을 얻기 위해 조금 더 조정할 수 있습니다. –

0

버튼에 이벤트 ItemUpdating이 필요하면 버튼을 캡처 이벤트 클릭이 필요합니다. 다음과 같은 것 :

이 코드는 VB에서 제공됩니다.

Protected Sub buttonUpdate_Click(sender As Object, e As EventArgs) 

    FormView1.UpdateItem(True) 

End Sub 

그리고 당신은

<div class="actions"> 
     <asp:Button ID="buttonUpdate" runat="server" CausesValidation="True" **OnClick="buttonUpdate_Click"** CommandArgument='<%# Eval("GalleryId") %>' Width="60" CommandName="Update" Text="Update" /> 
     <asp:Button ID="buttonCancel" runat="server" CausesValidation="False" Width="60" CommandName="Cancel" Text="Cancel" /> 
</div> <!-- .actions --> 
관련 문제