473,385 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

AutoPostBack

Hello

I have several controls in the center and bottom of the page that have to
perform some server side events. Is there a way that I can force the browser
to remember the location of the last control, i.e. if I click on a
dropdownlist that fires an event, for the browser to return to the same
control after postback?
Nov 19 '05 #1
6 3033
The server code should send back to the client the id of the control that
initiated the postback. In body's onload event you can send focus on the
control with matching id.

Eliyahu

"walterd" <wa*****@ananzi.co.za> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
Hello

I have several controls in the center and bottom of the page that have to
perform some server side events. Is there a way that I can force the browser to remember the location of the last control, i.e. if I click on a
dropdownlist that fires an event, for the browser to return to the same
control after postback?

Nov 19 '05 #2
You will need to use client side coding to set the focus of any particular
field.

In order to direct that focus from the server side you could set the value
of a hiddent HTML field to the name or index of the desired control.

Then the load event for the client page, you need to setfocus to the desired
control using that value


"walterd" <wa*****@ananzi.co.za> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
Hello

I have several controls in the center and bottom of the page that have to
perform some server side events. Is there a way that I can force the
browser
to remember the location of the last control, i.e. if I click on a
dropdownlist that fires an event, for the browser to return to the same
control after postback?

Nov 19 '05 #3
SMARTNAVIGATION in asp.net is for "persisting the scroll position when moving
from page to page." and "persisting element focus between navigations."

but , if you google, you will find lot of reports/questions abt smart
navigation not working on browsers other than IE (and some cases in IE too!)
...

SMARTNAVIGATION is the simplest way, but this feature may be limited to
latest IE users.

http://search.microsoft.com/search/r...Navigation&s=1

it is also possible with a simple function .. have a function like below

/// <param name="ControlClientId">pass the Control.ClientID of the server
control you need focus on</param>
private void SetFocus(string ControlClientId)
{
System.Text.StringBuilder strJScript = new System.Text.StringBuilder();
strJScript.Append("<SCRIPT>");
strJScript.Append("document.forms[0].");
strJScript.Append(ControlClientId);
strJScript.Append(".focus();");
strJScript.Append("</SCRIPT>");
Page.RegisterStartupScript("focus",strJScript.ToSt ring());
}

from each post back event, say inside a ddl_chnage event make a call like
below..

SetFocus(ddl.ClientID);

you can build a more Sophisticated solution by setting a hidden control with
the name of last changed HTML control (using onchange javascript event) and
call this same function to set focus on that..
"walterd" wrote:
Hello

I have several controls in the center and bottom of the page that have to
perform some server side events. Is there a way that I can force the browser
to remember the location of the last control, i.e. if I click on a
dropdownlist that fires an event, for the browser to return to the same
control after postback?

Nov 19 '05 #4
walterd wrote:
Hello

I have several controls in the center and bottom of the page that have to
perform some server side events. Is there a way that I can force the browser
to remember the location of the last control, i.e. if I click on a
dropdownlist that fires an event, for the browser to return to the same
control after postback?


This can be easily done with some anchor tags and javascript. See

http://dotnetjunkies.com/Article/E47...CB3C4A1AB.dcik
--
Rob Schieber
Nov 19 '05 #5
Here's some code that will return the window to whatever position it
was at before the PostBack:

<input type="hidden" name="MouseY" value="0" size="4">

<script language="JavaScript1.2">
<!--

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEDOWN)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
try
{
if (IE) { // grab the x-y pos.s if browser is IE
tempY = document.documentElement.scrollTop;//event.clientY +
document.body.scrollLeft
} else { // grab the x-y pos.s if browser is NS
tempY = e.pageY
}

// catch possible negative values in NS4
if (tempY < 0){tempY = 0}

if (window.navigator.appName.toLowerCase().indexOf("n etscape") > -1)
{
document.forms["form1"].MouseY.value = tempY;
}
else
{
document.form1.MouseY.value = tempY
}
}
catch (e)
{}

return true
}

<%
if (Page.Request["MouseY"] != null && Page.Request["MouseY"].Length >
0)
{
Response.Write("window.scrollTo(0, " + Page.Request["MouseY"] + ");");

}
%>

//-->

</script>

Best of luck,

Matt Furnari

Nov 19 '05 #6
You don't even need the anchor tags!!

Just enter the lines:

<script language="JavaScript">
location.href="#<%= Request.Form("__EVENTTARGET") %>";
</script>

in front of the last </form> tag and it automatically scrolls to the last
autopost item.

"Rob Schieber" <sc******@hotmail.com> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
walterd wrote:
Hello

I have several controls in the center and bottom of the page that have to perform some server side events. Is there a way that I can force the browser to remember the location of the last control, i.e. if I click on a
dropdownlist that fires an event, for the browser to return to the same
control after postback?


This can be easily done with some anchor tags and javascript. See

http://dotnetjunkies.com/Article/E47...CB3C4A1AB.dcik
--
Rob Schieber

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Susan van Houen | last post by:
Hi All, How do I intercept an autopostback on the client side and prevent it from executing the submit? In classic ASP I used to intercept the on_submit and just return false;
8
by: Matthew Louden | last post by:
why need to set autopostback property to be true?? I know autopostback event means to send the form to the server automatically. I tried checkbox, checkbox list, radio button, and radio button...
4
by: Scott M. | last post by:
If I put RequiredFiledValidators on a page and set them up with corresponding TextBoxes everything works just fine. If I add a DropDownList and set its AutoPostBack to True, I am able to post data...
6
by: Sunil | last post by:
Dear All I am a bit confused about AutoPost Back. My concept about AutoPostBack is that If AutoPostBack i "TRUE" for a Web Form the Web Form Goes back to the server and displays a fresh copy of...
0
by: Scott | last post by:
Hi. I'm having some problems with AutoPostBack in my asp.net pages running on Windows 2003/IIS 6. The pages are really simple. For example, one of them contains two dropDownLists. The firstdrop...
2
by: Tom Edelbrok | last post by:
Question: Why does a button event (ie: Button1_Click) get executed on the first click for a textbox control which has 'autopostback=false', but doesn't get executed until a second click when...
3
by: Brad | last post by:
The first text on my form is a numeric field. I have a javascript that runs on this field for onkeyup (validate the key strokes and modifies fields on the screen) but when I do this and have the...
2
by: rn5a | last post by:
Assume that a user control has a TextBox (Page1.ascx) <asp:TextBox ID="txtName" runat="server"/> I am encapsulating the above user control in a ASPX page named Page1.aspx i.e. the ASPX page...
0
by: andy | last post by:
Hi, I have a form uses several dropdownlists to narrow a set of criteria. ( This is in turn used to control what is shown on a gridview. ) With each, the user selects an entry and then the next...
6
by: Peter | last post by:
ASP.NET 2.0 Visual Studio 2008 I have the following code and when the textbox displays and I press Enter while in the text box I get AutoPostBack, how do I stop AutoPostBack? TextBox txt =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.