This is a migrated thread and some comments may be shown as answers.

How to set focus for label or page last

2 Answers 303 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dhamodharan
Top achievements
Rank 1
Dhamodharan asked on 07 Feb 2011, 04:24 PM
Hi,

I am using radgrid in my page. i have asp:button. when i click the button i want to show error message below the button. but i have 5 grid in my page. so i am passing error message to label. but i want set focus the label. how to set this one?


Thanks in advance,
Dhamu.

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 08 Feb 2011, 08:15 AM
Hi Dhamu,


I am not sure about what is the condition for showing error on page and where the controls (Button and Label) are placed (inside grid or directly placed on page).

I am assuming that the Label is not in the viewable area and want to scroll to viewable area on showing error. If so try the following approach to scroll Label control to viewable area (from client side) and see whether it helps.

client code:
<script type="text/javascript">
    function pageLoad() {
        var label = document.getElementById("errorLabel");
        if (label.innerText == "Error") {
            label.scrollIntoView();
        }
    }
</script>

setting the error message:
protected void Button2_Click(object sender, EventArgs e)
{
     //  check for the condition
     Label1.Text = "Error"; // Show error message
}


my mark-up:
   <telerik:RadGrid ID="RadGrid1" runat="server">
   </telerik:RadGrid>
      . . . .
<asp:Button ID="Button2" runat="server" Text="Update" OnClick="Button2_Click" />
<asp:Label ID="errorLabel" runat="server" Text="Label"></asp:Label>


Could you elaborate the requirement if this is not the exactly what you are looking for?


-Shinu.
0
Dhamodharan
Top achievements
Rank 1
answered on 08 Feb 2011, 11:25 AM
Hi Shinu,

Thanks for your response. and also your code very helpful for me. but i have change little bit.

 

 

function pageLoad() {

 

 

 

var label = document.getElementById('<%=lblErrMsg.ClientID%>');
label.scrollIntoView(true);
}

It is working fine.

Thanks,
Dhamu

 

Tags
Grid
Asked by
Dhamodharan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Dhamodharan
Top achievements
Rank 1
Share this question
or