2013-06-05 5 views
0

라디오 버튼으로 옵션을 선택한 후 다시 게시 할 때 문제가 있습니다. "예"를 선택한 후에는 텍스트 상자를로드하기 위해 다시 게시해야합니다. 그러나 선택하지 않으면 텍스트 상자가 나타나서는 안됩니다.라디오 버튼 포커스가 포스트 백 이후에 사라짐

http://www.codeproject.com/Articles/17571/Maintain-focus-between-postbacks-in-ASP-NET-2-0-al (내 "CurrentControl is"의 라디오 버튼을 추가 했음) 내 사이트에서 다른 포스트 백스톱 문제에 대한 해결책을 찾았습니다. 그러나 나 자신을 넘어선 이유 때문에 라디오 버튼.

방금 ​​계정을 만들었으므로 사진을 게시 할 수는 없지만 페이지가 다시 게시되면 포커스는 마지막 텍스트 상자 나 포커스가있는 드롭 다운 목록으로 이동합니다.

영문 라디오 버튼에 대한 :

<table class="dataentry"> 
    <tr> 
      <td class="column1"> 
       <asp:Label ID="lblPrevEmployed" runat="server" Text="Have you ever been employed by our company?"meta:resourcekey="lblPrevEmployed"></asp:Label> 
      </td> 
      <td class="column2"> 
       <asp:RadioButton ID="rdoPrevEmployed_Yes" runat="server" GroupName="PrevEmployed" AutoPostBack="True" OnCheckedChanged="rdoPrevEmployed_OnCheckedChanged" Text="Yes" meta:resourcekey="rbPrevEmployedYes" /> &nbsp; 
       <asp:RadioButton ID="rdoPrevEmployed_No" runat="server" GroupName="PrevEmployed" AutoPostBack="True" OnCheckedChanged="rdoPrevEmployed_OnCheckedChanged" Text="No" meta:resourcekey="rbPrevEmployedNo" /> 
       <asp:CustomValidator ID="cvPrevEmployed" runat="server" ErrorMessage="You must select either Yes or No." ValidationGroup="Group" OnServerValidate="cvPrevEmployed_ServerValidate" Display="Dynamic" meta:resourcekey="cvPrevEmployed"></asp:CustomValidator> 
      </td> 
    </tr> 
</table> 

답변

0

이 같은 것을보십시오 : 는

한 사업부가 라디오 버튼 목록과입니다 (나는 RadioButtonList 대신 개별 RadioButtons를의 사용했습니다) 두 번째 div는 선택된 라디오 버튼과 관련된 설명을 표시하기위한 것입니다.

또한 알림 레이블이 메시지로 활성화됩니다 (기본적으로 비활성화 됨).

[HTML]

<asp:Label ID="NotifyLabel" runat="server" Text="" ForeColor="Red" Font-Bold="true"></asp:Label> 
<br /> 
<div id="SelAccTypeSelect" runat="server" style="float: left; margin-right: 20px;"> 
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"> 
    <asp:ListItem Value="0" Text="Account Type 1" /> 
    <asp:ListItem Value="1" Text="Account Type 2" /> 
</asp:RadioButtonList> 
</div> 
<div id="SelAccTypeDesc" runat="server" style="width: 920px;"></div> 

라디오 버튼의 값에 대응 가능한 설명을 포함하고있는 배열이다.

[CODE BEHIND]

private void InitializeSelAccTypeDesc() 
{ 
SelAcctDescription[0] = "<p>This account type is for users who want to do something like this.</p>"; 
SelAcctDescription[1] = "<p>This account type is for other users who want to do something like that.</p>"; 
} 

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
// get the selected account type 
AccTypeByte = Convert.ToByte(RadioButtonList1.SelectedValue.ToString()); 

     // notify the user with the value of the selected radio button 
NotifyLabel.Visible = true; 
NotifyLabel.Text = string.Format("{0} was the value selected. - ", AccTypeByte); 

// replace the html in the div with the html from the selected array element 
SelAccTypeDesc.InnerHtml = SelAcctDescription[Convert.ToInt32(AccTypeByte)]; 
} 

* 참고 : 0 '없음'이 될 수 있으며, 1 '예'당신은 추가 할 수 NotifyLabel 주위에 문 만 쇼에의 값을 기준으로하는 경우가 될 수 AccTypeByte.

+0

컨텍스트에서 코드를 볼 수있는 방법이 있습니까? 이것이 내가하는 일에 적용될 수 있다고 생각하지만 현재 코드가 실제로 초점을 맞추기 위해 무엇을하는지 명확하지 않습니다. 응답 주셔서 감사합니다! – GeosefKerol

관련 문제