Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jump to another part of the same page after a postback 1

Status
Not open for further replies.

cesark

Programmer
Dec 20, 2003
621
0
0
Is there a way with ASP.NET that after the page is post back jump to another location of the same page? For example, when a user clicks on a LinkButton control in ‘offer_details.aspx’ page, jump to a location of the page so that is visible a specified table from the bottom of the page.

Thank you
 
Paste both your HTML and Code-Behind files as it works fine here...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
i had to make the same change that cesark did. appearently, a .net page will not jump to an anchor tag. i even tried <a href="#bottom">test</a> at the top of my page, and that link didn't work either. i have achieved what i needed to, thanks much for all your help.
 
appearently, a .net page will not jump to an anchor tag
That is incorrect. There is no such thing as a .net page. All ASP.NET does is omit HTML to the browser and HTML browsers are perfectly capable of jumping to an anchor tag.

As I said above, if you post your test code, using my latest example, we can see where you have gone wrong as both I and many other users on this site has used it successfully.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
no need to. as i said, it is working the way i want it to. besides, i have alreasy posted all relevant code.

thanks - brian.
 
no need to. as i said, it is working the way i want it to. besides, i have alreasy posted all relevant code.
Maybe you do have another way working successfully, but I'm intrigued as to why your other attempt didn't work - this site also works both ways and future readers of this post may benefit from others mistakes if they are highlighted and a solution given to them.

I'm not sure where you have "alreasy posted all relevant code" though as I can't recall seeing it anywhere above?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
hot sure what exactly you want me to do? here's what didn't work:

sub Page_Load()
if ispostback then
...
Dim sbFocus As New StringBuilder
sbFocus.Append("<script language='javascript'>" &
Environment.NewLine)
sbFocus.Append("window.location.href='#bottom'"
&Environment.NewLine)
sbFocus.Append("</script>")
Page.RegisterStartupScript("FocusScript",
sbFocus.ToString)
end if
end sub

<html>
<body>
<a href="#bottom">test</a>
<table>
.....table contents...
</table>
<a id="bottom" />
</body>
</html>
 
No, sorry I meant the actual HTML that was generated (i.e. from View Source once your page has loaded).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Here's what I did for a similar problem. I put the table in a form, then used javascript to make the form appear when I clicked on a button, although you can use a link instead:

<code>

<script>

function hidefields()
{

document.getElementById('fnametd').style.visibility = 'hidden';

document.getElementById('lnametd').style.visibility = 'hidden';

document.getElementById('companytd').style.visibility = 'hidden';

document.getElementById('emailtd').style.visibility = 'hidden';

document.getElementById('Submit_info').style.visibility = 'hidden';

document.getElementById('trspacer1').style.visibility = 'hidden';

document.getElementById('trspacer2').style.visibility = 'hidden';
}

function showfields()
{

document.getElementById('fnametd').style.visibility = 'visible';

document.getElementById('lnametd').style.visibility = 'visible';

document.getElementById('companytd').style.visibility = 'visible';

document.getElementById('emailtd').style.visibility = 'visible';

document.getElementById('Submit_info').style.visibility = 'visible';

document.getElementById('trspacer1').style.visibility = 'visible';

document.getElementById('trspacer2').style.visibility = 'visible';

document.getElementById('no_thanks').style.visibility = 'hidden';
}



function hide(i)
{
document.getElementById(i).style.visibility = 'hidden';
}

function show(i)
{
document.getElementById(i).style.visibility = 'visible';
}
</script>








</code>


Then you use the function in your tag:


<a onclick="javascript:showfields()"><IMG src="images/Loginbutton.gif"></a>



This one was for individual fields, but just replace showfields() with show(i) where I is the form id, and it will work.




Or you can create 2 versions of the page, and have it load the table version when you press the button.
 
You really don't need it to be as complicated as that...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Well you only need this part:


function hide(i)
{
document.getElementById(i).style.visibility = 'hidden';
}

function show(i)
{
document.getElementById(i).style.visibility = 'visible';
}
</script>



Then you use the function in your tag:


<a onclick="javascript:showfields()"><IMG src="images/Loginbutton.gif"></a>


That's pretty simple.
 
It still doesn't need to hide and show elements. The elements already exist so it's just a case of scrolling down to them with "window.location.href='#bottomOfTable'" and that's it!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
i kust posted what the html is. the only difference is the script is after the </table>, but before the </html>.

like i said before, it works fine when i use the id of the table row.
 
You haven't posted the HTML. You posted this:
Code:
<html>
<body>
 <a href="#bottom">test</a>
 <table>
   .....table contents...
 </table>
 <a id="bottom" />
</body>
</html>
which couldn't possibly work whichever solution you use as the page will not have scrollbars due to it's length and so clicking the first anchor tag will have no effect.

It's fairly clear we are getting nowhere now, and this thread has simply become a mess and it's pointless continuing with it as it will be unclear for any future readers, so for any of those readers, here's a simple summary of what to do:


1) Add an anchor tag of where you want the page to scroll to:
Code:
<a id="myAnchor" />

2) Once you have ran the relevant code in your page, make a call to this function:
Code:
    Private Sub FocusControl(ByVal ctrl As Control)
        Dim sbFocus As New StringBuilder
        sbFocus.Append("<script language='javascript'>" & Environment.NewLine)
        sbFocus.Append("window.location.href='#" + ctrl.ClientID & "';" & Environment.NewLine)
        sbFocus.Append("</script>")
        Page.RegisterStartupScript("FocusScript", sbFocus.ToString)
    End Sub


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
no need to get upset, ca8msm. my table is longer than a page. i didn't post it because what's in the table is not relevant. you are right about not getting anywhere, like i said before you wanted the html, it's works when i used cesark solution. thanks for all the help.
 
I'm not getting upset - I just can't believe how such a simple solution has turned into such a large post and for future readers it looks as though it is quite hard to implement when it is in fact very very simple.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top