Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written below code in radio button list check change event
C#
protected void rblStatus_SelectedIndexChanged(object sender, EventArgs e)
    {
        //To get focus on radio button which is selected
        var script = string.Format("document.getElementById('{0}_{1}').focus();", rblStatus.ClientID, rblStatus.SelectedIndex);

        if (ScriptManager.GetCurrent(this) != null && ScriptManager.GetCurrent(this).IsInAsyncPostBack)
        {
            ScriptManager.RegisterStartupScript(rblStatus, typeof(RadioButtonList), Guid.NewGuid().ToString(), script, true);
        }
        else
        {
            ClientScript.RegisterStartupScript(typeof(RadioButtonList), Guid.NewGuid().ToString(), script, true);
        }

        //	Open - 1
        //  Close - 2
        //	Extension - 3
        //  Completion - 4	
        //	Inprogress - 5
        
        List<CorrectiveActionExtension> correctiveActionStatus = new List<CorrectiveActionExtension>();
        correctiveActionStatus = (List<CorrectiveActionExtension>)ViewState["dataSource"];

        int i = 0;
        foreach (CorrectiveActionExtension CAItem in correctiveActionStatus)
        {

            if (i == int.Parse(ViewState["index"].ToString()))
            {
                txtDescription.Text = CAItem.Remarks.ToString();

                if (rblStatus.SelectedValue.Equals("3"))
                {
                    divTargetDate.Visible = true;
                    ulTargetDate.DateTime = (CAItem.TargetDate == null ? DateTime.Now : CAItem.TargetDate);
                }
                else
                {
                    divTargetDate.Visible = false;
                    ulTargetDate.DateTime = null;
                   // txtDescription.T
                }

            }
            i++;
        }
        mdlChangeStatus.Show();
    }


In which code used to get focus on radio buttonlist is
C#
var script = string.Format("document.getElementById('{0}_{1}').focus();", rblStatus.ClientID, rblStatus.SelectedIndex);

        if (ScriptManager.GetCurrent(this) != null && ScriptManager.GetCurrent(this).IsInAsyncPostBack)
        {
            ScriptManager.RegisterStartupScript(rblStatus, typeof(RadioButtonList), Guid.NewGuid().ToString(), script, true);
        }
        else
        {
            ClientScript.RegisterStartupScript(typeof(RadioButtonList), Guid.NewGuid().ToString(), script, true);
        }

Now my issue is while loading this i dont get focus on selected radio button from radio button list.
Please help me to solve this.
Posted
Comments
AnkitGoel.com 11-Dec-12 1:50am    
what do u mean by while loading this? please elaborate.
CSR89 11-Dec-12 1:53am    
This is a modalPopup window. While loading this any one of radio button is selected. That depends on situation. I need focus on selected radio button

1 solution

You should set focus on rblStatus and not on individual selected list item. Need to do something like this:


document.getElementById('<%= rblStatus.ClientID %>').focus();
 
Share this answer
 
Comments
CSR89 11-Dec-12 2:04am    
Its not working
CSR89 11-Dec-12 7:21am    
Is there any solution for solve this issue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900