4 Replies - 3463 Views - Last Post: 20 May 2015 - 06:57 AM Rate Topic: -----

#1 November-06   User is offline

  • D.I.C Regular

Reputation: 54
  • View blog
  • Posts: 482
  • Joined: 04-January 11

Set focus on a panel

Posted 20 May 2015 - 04:10 AM

I know this sounds easy and there may be a lot of materials in the internet that discuss this but I'm not getting the correct results so I'm asking this here.

How can I set focus to a panel that is inside an updatePanel?

It is located at the topmost part of the page. When a button on the bottom is clicked, it should return focus to the topmost part of the page wherein the panel is.

I have tried panel1.focus() and even call document.getElementById('panel1ClientID').focus() from C# using Page.ClientScript but they didn't work.

I need to add, my button click event is called from javascript. My button is also on another update panel.

This post has been edited by November-06: 20 May 2015 - 04:15 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Set focus on a panel

#2 djjeavons   User is offline

  • D.I.C Regular
  • member icon

Reputation: 114
  • View blog
  • Posts: 417
  • Joined: 09-January 09

Re: Set focus on a panel

Posted 20 May 2015 - 05:28 AM

Hi

Maybe I am looking at this too simplistically, but could you not just use an anchor tag and then use the location.href on the click of the button to jump back to the top of the page?

<asp:UpdatePanel runat="server" ID="updatePanel">
	<ContentTemplate>
		<asp:Panel runat="server">
			<a name="myPanelAnchor" />
			My panel contents
		</asp:Panel>
	</ContentTemplate>
</asp:UpdatePanel>
...... 'Loads of content
<input type="button" value="Click Me" onclick="location.href = '#myPanelAnchor'" />


Was This Post Helpful? 0
  • +
  • -

#3 November-06   User is offline

  • D.I.C Regular

Reputation: 54
  • View blog
  • Posts: 482
  • Joined: 04-January 11

Re: Set focus on a panel

Posted 20 May 2015 - 05:37 AM

I apologise for forgetting to mention that my button is performing some client-side and then some server-side commands. After processing, it will display a success/error message in the panel located at the top of the page.

I also tried scriptManagerId.SetFocus(panelId) but it doesn't work either.

This post has been edited by November-06: 20 May 2015 - 05:38 AM

Was This Post Helpful? 0
  • +
  • -

#4 djjeavons   User is offline

  • D.I.C Regular
  • member icon

Reputation: 114
  • View blog
  • Posts: 417
  • Joined: 09-January 09

Re: Set focus on a panel

Posted 20 May 2015 - 05:52 AM

From what I understand, a Panel cannot receive focus. A control within the Panel can but the Panel itself is just a container.

However, ASP.NET offers the Page.SetFocus method which you can use to set focus to controls from the code behind (but not panels) which is what I am assuming you want to do based on the outcome of the process. So combining this with the anchor tag you could do:

Page.SetFocus(myAnchorTag.ClientID);



The only change to the markup is to the declaration of the anchor tag to have it runat server:

<a name="myPanelAnchor" id="myAnchorTag" runat="server" />


Was This Post Helpful? 1
  • +
  • -

#5 November-06   User is offline

  • D.I.C Regular

Reputation: 54
  • View blog
  • Posts: 482
  • Joined: 04-January 11

Re: Set focus on a panel

Posted 20 May 2015 - 06:57 AM

Playing around some more with the codes, controlName.Focus() and Page.SetFocus(controlName) both works.

You're right about not all controls can receive focus. What I did was use a LinkButton (got this from your anchor idea).

Thanks a lot. It now works.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1