Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
i have a page which has 5 tables to insert values ....my problem is that page is too long and i have to do validations on each table so while entering data into last table i have to enter multiple value one by one so page loads on every entry so page refreshes every time my problem is that i have to scroll down every time for entry in last table ,,,,,,,,can anyone suggest me any method in which everytime page reloads the focus should come back to the table i am entering values into so i dont to scroll down everytime
Posted
Updated 18-Apr-11 6:32am
v2

There is a solution which might help you

On every 5 table add the below property
onclick="MakeSelected(this)">


Below is the implementation of the

<script language="javascript" type="text/javascript">
       function MakeSelected(ctrl) {
           document.getElementById('<%= hdnVal.ClientID%>').value = ctrl.id;
       }
   </script

I created a hidden control on the page with the name "hdnVal" so that we can preserve the ID of the selected table.

Now before end of the <form> tag just add below code

<script language="javascript" type="text/javascript">
       if (document.getElementById('<%= hdnVal.ClientID%>') != null && document.getElementById('<%= hdnVal.ClientID%>').value != "")
           document.getElementById(document.getElementById('<%= hdnVal.ClientID%>').value).focus();
   </script>


SO your code would look like that
<head runat="server">
    <script language="javascript" type="text/javascript">
        function MakeSelected(ctrl) {
            document.getElementById('<%= hdnVal.ClientID%>').value = ctrl.id;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="hidden" runat="server" id="hdnVal" />
        <table width="600" cellpadding="0" cellspacing="0" id="table1" onclick="MakeSelected(this)">
            <tr>
                <td>
                </td>
            </tr>
        </table>
    </div>
    <script language="javascript" type="text/javascript">
        if (document.getElementById('<%= hdnVal.ClientID%>') != null && document.getElementById('<%= hdnVal.ClientID%>').value != "")
            document.getElementById(document.getElementById('<%= hdnVal.ClientID%>').value).focus();
    </script>
    </form>
</body>
 
Share this answer
 
v2
You could try this - save the currently focused cell as a session variable, and if that session variab;le isn't null, set focus back to it. I don't know if it would work, but, well, you know...
 
Share this answer
 
Comments
thatraja 18-Apr-11 12:50pm    
Comment from OP(Moved from answer):
@john how do u get currently focused cell
i think you want to remain scroll position still after postback

for that use ajax update panel and write the below code in your source code

<%@ Page Title="" Language="C#" MasterPageFile="~/StudentHome.master" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeFile="LessonView.aspx.cs" Inherits="Student_LessonView"%>
 
Share this answer
 
v2
Causing a postback each time a table is updated (every cell? even worse!) is VERY BAD USER EXPERIENCE. Don't do it. Instead, you want one or both of:

- Client side validation. Use Javascript to check that the values being entered are sane, e.g. numeric, in the right static range and other things that can be checked immediately. You can also use AJAX to perform validation against server side state, but the question of what to do if AJAX validation fails is more tricky since the user will have moved the focus and be in another control by the time it comes back.

- Validate the whole page in a single form submission at the end (when the user hits the Submit button), and highlight errors in the returned page if there were any.

I recommend a combination, with static validation in JS on the client side and validation against the database in the page that is called as the submit handler.
 
Share this answer
 
@nitin so you have to add hdnVal on each table
 
Share this answer
 
Comments
nit_singh 18-Apr-11 14:37pm    
No, you have to add only a single hidden field on the entire page so that you can preserve the focused table ID.
usernetwork 18-Apr-11 14:40pm    
is there any way to do it without java sript using c# code ??
Orcun Iyigun 18-Apr-11 14:43pm    
Prejval, when you want to say something(comment) on an anwer use the "Add comment" button under the solution. Please do not use the "Add a solution button".When you use the "add comment" button then the person will be notified otehrwise he wont. In addition to this, reposting the question is not a good idea. you are filling the threads with duplicate threads. I see this thread is identical to this question" http://www.codeproject.com/Questions/183441/scrolling-problem-in-asp-net-page-too-long.aspx ".
usernetwork 18-Apr-11 14:45pm    
ya i am new to codeproject so didnt knew it .....i was trying to reframe my question so more nn more people read it ,,,,,,,,,thanks a lot
Orcun Iyigun 18-Apr-11 17:07pm    
For renaming your project under the question tehre is a button named "Improve Question" you can edit your question there. As well tehre is a reply button on each comment :)

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