Showing posts with label back. Show all posts
Showing posts with label back. Show all posts

Saturday, March 24, 2012

Set Focus and post back on Dropdown List

I have a dropdown list that hides certain rows in a datagrid.

The focus remains on the dropdown list after the postback and I am trying to get it away from it because the user may and does want to use the mouse wheel to scroll down, but since the focus is on the ddl, they may not see it and it will resort.

Here is my set focus code which works fine on page load event...


Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim s As String = "<SCRIPT language='javascript'>document.getElementById('" & ctrl.ID & "').focus() </SCRIPT>"
RegisterStartupScript("focus", s)
End Sub

And this code is for the page load event...


If Not IsPostBack Then
Me.SetFocus(Me.txtSearch)
End If

I have been trying to place the Me.SetFocus(Me.txtSearch) where the postback of the ddl occurs in the code, such as the reBind() or the ddlTypes_SelectedIndexChanged() and the dgServer_ItemDataBound() which has the ddl code.
None seem to work, but it works on page load event.

Suggestions?

Thanks all,

Zath
This should work fine from your ddlTypes_SelectedIndexChanged() event handler. Are calling this method only if the IsPostBack property is false? If so, that could be your problem.

Have you tried putting the SetFocus in the Page_PreRender? This runs after the event code.


Private Sub Page_PreRender(ByVal sender AS Object,VyVal e AS System.EventArgs) Handles MyBase.PreRender
If ispostback=true then
Me.SetFocus(Me.txtSearch)
End if
End Sub

You can use
If Not ispostback
if necessary.
check out my component here :view post 821121

regards

Tuesday, March 13, 2012

Set page to focus some certain location after post back

Hi,
I have a web form, after post back to itself, I need to make web page
scroll to some certian location instead of top. We only care IE.
Anybody has some idea how to do it?
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours HardyIf you want a purist MS position, look at Smart Navigation.
//C#
Page.SmartNavigation=true;
Another option:
http://aspnet.4guysfromrolla.com/ar...111704-1.2.aspx
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Hardy Wang" wrote:

> Hi,
> I have a web form, after post back to itself, I need to make web page
> scroll to some certian location instead of top. We only care IE.
> Anybody has some idea how to do it?
> --
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
>
>
Not maintain post back position, but scroll to certain location.
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Cowboy (Gregory A. Beamer) - MVP" <NoSpamMgbworld@.comcast.netNoSpamM> wrote
in message news:0C35D26C-5F0F-4DDB-A56A-BFCD12B5CB51@.microsoft.com...
> If you want a purist MS position, look at Smart Navigation.
> //C#
> Page.SmartNavigation=true;
> Another option:
> http://aspnet.4guysfromrolla.com/ar...111704-1.2.aspx
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> ***************************
> Think Outside the Box!
> ***************************
> "Hardy Wang" wrote:
>
You will probably need to do this by using Javascript and using anchor
tags.
Place name anchors throughout the page like:
<a name="top">Top</a>
<a name="middle">Middle</a>
<a name="bottom">Bottom</a>
Then you could push Javascript out from the code-behind something like:
<script>
window.navigate('#bottom');
</script>
The page would then scroll to the bottom. Just make sure your
javascript appears last in the page after all the sections of the page
have been named...
If you know the postition you want.
//client side script
function __dascwebLoadScrollPosition( top, left )
{
window.document.body.scrollLeft = top;
window.document.body.scrollTop = left;
}
You can set the scrollLeft and scrollTop of the body. If you don't know the
position, you can do aa7im suggested with anchor tags.
bill
"Hardy Wang" <hardywang@.hotmail.com> wrote in message
news:%23HRqRkV3EHA.208@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I have a web form, after post back to itself, I need to make web page
> scroll to some certian location instead of top. We only care IE.
> Anybody has some idea how to do it?
> --
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
>

Set page to focus some certain location after post back

Hi,
I have a web form, after post back to itself, I need to make web page
scroll to some certian location instead of top. We only care IE.
Anybody has some idea how to do it?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours HardyIf you want a purist MS position, look at Smart Navigation.

//C#
Page.SmartNavigation=true;

Another option:
http://aspnet.4guysfromrolla.com/ar...111704-1.2.aspx

--

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Hardy Wang" wrote:

> Hi,
> I have a web form, after post back to itself, I need to make web page
> scroll to some certian location instead of top. We only care IE.
> Anybody has some idea how to do it?
> --
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
>
Not maintain post back position, but scroll to certain location.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Cowboy (Gregory A. Beamer) - MVP" <NoSpamMgbworld@.comcast.netNoSpamM> wrote
in message news:0C35D26C-5F0F-4DDB-A56A-BFCD12B5CB51@.microsoft.com...
> If you want a purist MS position, look at Smart Navigation.
> //C#
> Page.SmartNavigation=true;
> Another option:
> http://aspnet.4guysfromrolla.com/ar...111704-1.2.aspx
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> ***************************
> Think Outside the Box!
> ***************************
> "Hardy Wang" wrote:
>> Hi,
>> I have a web form, after post back to itself, I need to make web page
>> scroll to some certian location instead of top. We only care IE.
>> Anybody has some idea how to do it?
>>
>> --
>> WWW: http://hardywang.1accesshost.com
>> ICQ: 3359839
>> yours Hardy
>>
>>
>
You will probably need to do this by using Javascript and using anchor
tags.

Place name anchors throughout the page like:

<a name="top">Top</a>
<a name="middle">Middle</a>
<a name="bottom">Bottom</a
Then you could push Javascript out from the code-behind something like:

<script>
window.navigate('#bottom');
</script
The page would then scroll to the bottom. Just make sure your
javascript appears last in the page after all the sections of the page
have been named...
If you know the postition you want.

//client side script
function __dascwebLoadScrollPosition( top, left )
{
window.document.body.scrollLeft = top;
window.document.body.scrollTop = left;
}

You can set the scrollLeft and scrollTop of the body. If you don't know the
position, you can do aa7im suggested with anchor tags.

bill

"Hardy Wang" <hardywang@.hotmail.com> wrote in message
news:%23HRqRkV3EHA.208@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I have a web form, after post back to itself, I need to make web page
> scroll to some certian location instead of top. We only care IE.
> Anybody has some idea how to do it?
> --
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy