473,386 Members | 1,775 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,386 software developers and data experts.

What Control Caused the PostBack?

Is there any way to dynamically get the name of the control that caused the
postback? Since SmartNav is not working for me I'm trying to implement a way
to scroll to the control that caused the post back so the user does not have
to scroll all the time.

I got the script working great and everything else, but I want to be able to
tell the name of the control that posted back. That way we don't have to
hard code much at all.

This is what I have implemented so far:

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender

' automatically scroll to the object that posted back (if applicable)

If Page.IsPostBack > 0 Then

RegisterStartupScript("scroll", "<script language=javascript>" +
_scrollToObjectPath + _scrollToObjectName + ".scrollIntoView();</script>")

End If

End Sub
Thanks in advance,
- Jeff
Nov 17 '05 #1
2 1638
You may be able to get it from Request.Form("__EVENTTARGET"), but AFAIK
that's only generated by asp.net if one of your controls, such as a
combobox, has it's AutoPostBack property set to True. I'm not 100% sure on
that.

"Jeff Voigt" <je***********@djj.state.fl.us> wrote in message
news:ez**************@TK2MSFTNGP12.phx.gbl...
Is there any way to dynamically get the name of the control that caused the postback? Since SmartNav is not working for me I'm trying to implement a way to scroll to the control that caused the post back so the user does not have to scroll all the time.

Nov 17 '05 #2
"Jeff Voigt" <je***********@djj.state.fl.us> wrote in message
news:ez**************@TK2MSFTNGP12.phx.gbl...
Is there any way to dynamically get the name of the control that caused the postback? Since SmartNav is not working for me I'm trying to implement a way to scroll to the control that caused the post back so the user does not have to scroll all the time.


Jeff, you could look at the value of the __EVENTTARGET hidden field via
Request.Form["__EVENTTARGET"].

You should note that although this will work in many cases, it won't work
for all. ASP.NET searches the control tree looking for a control with its
ClientID equal to __EVENTTARGET and implementing IPostBackEventHandler. If
found, it will pass __EVENTTARGET and __EVENTARGUMENT to this controls
RaisePostBackEvent method.

Usually, __EVENTTARGET is the ClientID of a single control in a single place
on the page. But a composite control may have many child controls which can
post back, and __EVENTTARGET may only name a single hidden field located in
front of all of those child controls. The composite control might then use
__EVENTARGUMENT to distinguish which child control caused the postback, but
you would be unable to do so.

Another issue would be the case where a button causes the postback, but that
it is "clicked" via its accessKey attribute. This button might not be
anywhere near where the user was working when he pressed the access key.

Is there anything in the DOM which would give you a better idea of "what
part of the window is visible right now"? If so, you might capture onsubmit
and cause that information to be sent to the host, which could send it back
to the page in the response. Code in the onload handler on the page might
then be able to restore that information.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #3

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

Similar topics

5
by: vbMental | last post by:
Is there anyway to find out which control fired the postback in server-side code? Like in windows programming "Form.ActiveControl" ?
5
by: Joey G | last post by:
How do I get the name or identify the control that caused the page postback. I need the information during page init. Reason why, because I need to tell usercontrol_1 that usercontrol_2 button was...
3
by: Jordan | last post by:
I am dynamically inserting an html <input> tag as text (equivalent of an image button) into a page via a Literal control. Something like this gets inserted: <input type="image"...
4
by: dchillman | last post by:
string ctrlname = page.Request.Params.Get("__EVENTTARGET"); if (ctrlname != null && ctrlname != string.Empty) { return this.Page.FindControl(ctrlname); } I have a form on which I was trying...
5
by: TS | last post by:
Is there a way in debug mode to determine what event caused the postback to occur without having an event handler for that event? thanks
2
by: news.microsoft.com | last post by:
How can I tell which control caused a postback? I have several controls that cause a postback, and I want to take different actions depending on which was activated. It seems a little backward...
2
by: sunilthk | last post by:
Hi All, I have a question. If javascript is disabled how asp.net determines which control has caused the post back. As we know that when we clicks on the button the buttons name goes with posted...
4
by: pamelafluente | last post by:
I am trying to pass a javascript variable to ASP. It almost works, except for the postback part. Infact if one clicks on the div and on the button it can be seen that the variable passes...
3
by: | last post by:
Hi all, I have a CheckBoxList control which has about 10 items. I have set autopostback=true and also set an eventhandler for OnSelectedIndexChanged. The problem is I want to identify which...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.