2011-08-22 3 views
0

동적으로 생성 된 ASP.net 페이지의 GridView 항목이있는 응용 프로그램에서 작업 중이며 그리드보기 내에서 항목이 업데이트 될 때 부분적으로 포스트 백이 발생합니다. 이 부분적인 포스트 백이 탭 순서를 잃어 버리거나 탭 순서가 다시 시작될 때 무시됩니다. 그리드보기 자체에는 그리드보기의 수정 된 항목에서 새 값을 계산하기 위해 캐치되는 사전 렌더링이 이미 있습니다. 사전 렌더링 호출 이전에 어떤 요소가 페이지의 포커스를 얻었는지 얻을 수있는 방법이 있습니까? 보낸 사람 개체는 그리드보기 자체입니다.실제 포커스가 손실 된 실제 요소

답변

0

이 함수를 사용하면 다시 게시를 일으킨 컨트롤을 반환 할 수 있습니다. 이렇게하면 다시 선택하거나 다음 탭 색인을 찾을 수 있습니다.

private Control GetControlThatCausedPostBack(Page page) 
    { 
     //initialize a control and set it to null 
     Control ctrl = null; 

     //get the event target name and find the control 
     string ctrlName = Page.Request.Params.Get("__EVENTTARGET"); 
     if (!String.IsNullOrEmpty(ctrlName)) 
      ctrl = page.FindControl(ctrlName); 

     //return the control to the calling method 
     return ctrl; 
    } 

다음은 변경시 AJAX를 통해 합계를 업데이트 한 입력을 동적으로 생성 한 인스턴스입니다. 이 코드를 사용하여 포스트 북을 초래 한 컨트롤의 탭 인덱스를 기반으로 다음 탭 인덱스를 결정했습니다. 분명히,이 코드는 제 사용법에 맞춰져 있지만, 약간의 조정만으로도 당신을 위해서도 효과가있을 것이라고 생각합니다.

int currentTabIndex = 1; 
WebControl postBackCtrl = (WebControl)GetControlThatCausedPostBack(Page);     

foreach (PlaceHolder plcHolderCtrl in pnlWorkOrderActuals.Controls.OfType<PlaceHolder>()) 
{ 
    foreach (GuardActualHours entryCtrl in plcHolderCtrl.Controls.OfType<GuardActualHours>()) 
    { 
     foreach (Control childCtrl in entryCtrl.Controls.OfType<Panel>()) 
     { 
      if (childCtrl.Visible) 
      { 
       foreach (RadDateInput dateInput in childCtrl.Controls.OfType<RadDateInput>()) 
       { 
        dateInput.TabIndex = (short)currentTabIndex; 
        if (postBackCtrl != null) 
        { 
         if (dateInput.TabIndex == postBackCtrl.TabIndex + 1) 
          dateInput.Focus(); 
        } 
        currentTabIndex++; 
       } 
      }       
     } 
    } 
}