专注于PostBack [英] Giving Focus on PostBack

查看:51
本文介绍了专注于PostBack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,我将焦点放在页面上的第一个文本框中:


< body onLoad =" document.forms [0] .firstName.focus() ;">


当我退出

我的屏幕上的第3个文本框时,我也去检查一些数据的状态。


问题是当页面回发时,屏幕跳回到第一个文本框,因为

onLoad语句。有没有一种简单的方法来

告诉它只进行一次Onload并转到重新发布的下一个文本框?


谢谢,


Tom

解决方案

我想这就是你想要的......


Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load


如果不是IsPostBack那么


< body onLoad =" document.forms [0] .firstName.focus();">


结束如果


End Sub


" tshad" < TS ********** @ ftsolutions.com>在留言中写道

新闻:ec ************** @ TK2MSFTNGP12.phx.gbl ...

我有一个页面我将焦点放在页面上的第一个文本框中:

< body onLoad =" document.forms [0] .firstName.focus();">
当我退出屏幕上的第3个文本框时,我也会检查一些数据的状态。

问题是屏幕跳回到第一个文本框因为
页面回发时的onLoad语句。是否有一个简单的方法
告诉它只进行一次Onload并转到
转发的下一个文本框?
谢谢,

Tom



" Andy G" < AJ ***** @ iastate.edu>在消息中写道

新闻:关于************** @ TK2MSFTNGP12.phx.gbl ...

我认为这是什么你想要的......

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理MyBase.Load

如果不是IsPostBack然后

< body onLoad =" document.forms [0] .firstName.focus();">

结束如果


我尝试了但是得到了错误:


编译器错误消息:BC30636:''>''预计。


我的代码是:


Sub Page_Load(发送者为对象,e为EventArgs)

,如果不是IsPostBack然后

< body onLoad =" document.forms [0] .firstName.focus();">

结束如果

end sub


Tom

" tshad" < TS ********** @ ftsolutions.com>在消息中写道
新闻:ec ************** @ TK2MSFTNGP12.phx.gbl ...

我有一个页面,我把焦点放在我页面上的第一个文本框:

< body onLoad =" document.forms [0] .firstName.focus();">

我也去了当我退出我的屏幕上的第三个文本框时,检查一些数据的状态。

问题是屏幕跳回到第一个文本框因为
页面回发时的onLoad语句。是否有一种简单的方法


告诉它只进行一次Onload并转到


转发的下一个文本框?


谢谢,

Tom




< blockquote>您好。

添加Runat =" server"和id =" myBody"到aspx文件中的body标签。然后

把它放在你的代码中:

受保护的WithEvents myBody As System.Web.UI.HtmlControls.HtmlGenericControl


现在你可以在你的页面加载方法中添加javascript,如下所示:

如果不是IsPostBack那么

myBody.Attributes.Add(" onLoad",

" document.forms [0] .the_id_of_the_first_textbox.focus();")

结束如果


Shawn


" tshad" < TS ********** @ ftsolutions.com>在消息中写道

news:uc ************** @ TK2MSFTNGP14.phx.gbl ...

" Andy G" < AJ ***** @ iastate.edu>在消息中写道
新闻:关于************** @ TK2MSFTNGP12.phx.gbl ...

我认为这就是你想要的......私有Sub Page_Load(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理MyBase.Load

如果不是IsPostBack那么

< body onLoad =" document.forms [0] .firstName.focus();">

结束如果

End Sub



我试过但得到了错误:

编译器错误消息:BC30636:''>''预期。

我的代码是:

Sub Page_Load(发件人为Object,e为EventArgs)
如果不是IsPostBack那么
< body onLoad =" document.forms [0] .firstName .focus();">
结束如果
结束了

Tom



" tshad" < TS ********** @ ftsolutions.com>在消息中写道
新闻:ec ************** @ TK2MSFTNGP12.phx.gbl ...

我有一个页面,我把焦点放在我页面上的第一个文本框:

< body onLoad =" document.forms [0] .firstName.focus();">

我也去了当我退出我的屏幕上的第三个文本框时,检查一些数据的状态。

问题是屏幕会跳回到第一个文本框,因为
页面回发时的onLoad语句是否有一个简单的


方式来

告诉它只进行一次Onload并转到


repost上的下一个文本框?


谢谢,

Tom





I have a page where I give focus to the first textbox on my page:

<body onLoad="document.forms[0].firstName.focus();">

I also go and check the status of some data when I exit the 3rd textbox on
my screen.

The problem is that the screen jumps back to the first textbox because of
the onLoad statement when the page is posted back. Is there an easy way to
tell it to do the Onload only once and to go the next textbox on the repost?

Thanks,

Tom

解决方案

I think this is what you want....

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then

<body onLoad="document.forms[0].firstName.focus();">

End If

End Sub

"tshad" <ts**********@ftsolutions.com> wrote in message
news:ec**************@TK2MSFTNGP12.phx.gbl...

I have a page where I give focus to the first textbox on my page:

<body onLoad="document.forms[0].firstName.focus();">

I also go and check the status of some data when I exit the 3rd textbox on
my screen.

The problem is that the screen jumps back to the first textbox because of
the onLoad statement when the page is posted back. Is there an easy way to tell it to do the Onload only once and to go the next textbox on the repost?
Thanks,

Tom



"Andy G" <aj*****@iastate.edu> wrote in message
news:On**************@TK2MSFTNGP12.phx.gbl...

I think this is what you want....

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then

<body onLoad="document.forms[0].firstName.focus();">

End If

End Sub

I tried that but got the error:

Compiler Error Message: BC30636: ''>'' expected.

My code is:

Sub Page_Load(sender as Object, e as EventArgs)
if not IsPostBack then
<body onLoad="document.forms[0].firstName.focus();">
end if
end sub

Tom

"tshad" <ts**********@ftsolutions.com> wrote in message
news:ec**************@TK2MSFTNGP12.phx.gbl...

I have a page where I give focus to the first textbox on my page:

<body onLoad="document.forms[0].firstName.focus();">

I also go and check the status of some data when I exit the 3rd textbox
on
my screen.

The problem is that the screen jumps back to the first textbox because of
the onLoad statement when the page is posted back. Is there an easy way


to

tell it to do the Onload only once and to go the next textbox on the


repost?


Thanks,

Tom




Hi.
Add a Runat="server" and id="myBody" to the body tag in the aspx file. Then
put this in your code behind:
Protected WithEvents myBody As System.Web.UI.HtmlControls.HtmlGenericControl

Now you can add the javascript in you page load method, like this:
If Not IsPostBack Then
myBody.Attributes.Add("onLoad",
"document.forms[0].the_id_of_the_first_textbox.focus();")
End If

Shawn

"tshad" <ts**********@ftsolutions.com> wrote in message
news:uc**************@TK2MSFTNGP14.phx.gbl...

"Andy G" <aj*****@iastate.edu> wrote in message
news:On**************@TK2MSFTNGP12.phx.gbl...

I think this is what you want....

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then

<body onLoad="document.forms[0].firstName.focus();">

End If

End Sub



I tried that but got the error:

Compiler Error Message: BC30636: ''>'' expected.

My code is:

Sub Page_Load(sender as Object, e as EventArgs)
if not IsPostBack then
<body onLoad="document.forms[0].firstName.focus();">
end if
end sub

Tom



"tshad" <ts**********@ftsolutions.com> wrote in message
news:ec**************@TK2MSFTNGP12.phx.gbl...

I have a page where I give focus to the first textbox on my page:

<body onLoad="document.forms[0].firstName.focus();">

I also go and check the status of some data when I exit the 3rd textbox
on
my screen.

The problem is that the screen jumps back to the first textbox because of the onLoad statement when the page is posted back. Is there an easy

way to

tell it to do the Onload only once and to go the next textbox on the


repost?


Thanks,

Tom





这篇关于专注于PostBack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆