AutoPostBack

W

walterd

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?
 
E

Eliyahu Goldin

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
 
M

Mr Newbie

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
 
G

Guest

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/results.aspx?view=msdn&st=b&na=82&qu=SmartNavigation&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.ToString());
}

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..
 
R

Rob Schieber

walterd said:
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/E474B0FC-20D2-48B3-93B5-DC4CB3C4A1AB.dcik
 
S

sp3d2orbit

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("netscape") > -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
 
F

Ferret Face

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

AutoPostback 2
AutoPostback 3
AutoPostBack Problems 0
Help with my responsive home page 2
dropdownlist autopostback with javascript confirm 5
Align img inside nav tabs section 5
AutoPostBack 2
Autopostback 1

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top