Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Please help with script. Mixing Javascript in my code-behind page.


Message #1 by "dave" <dougwood@a...> on Wed, 19 Feb 2003 23:16:45
can anyone help me out here? 
In my aspx page , I have a calendar control. All I'm trying to do is make 
it so that when a user clicks on a Calendar date, the browser jumps down 
to an <a> named 'bottom' instead of the default top of the page. 

In my aspx page, I have the code <a name="bottom"></a> 
Here is the pertinent code I have in my code behind page 
(calendar.aspx.cs): 
<code>
private void Jump(string url)

{

string NewCode = "<SCRIPT LANGUAGE = JavaScript>" + "function Jump()" 
+ "{window.location = '" + url + "' }" + "</SCRIPT>";

Response.Write(NewCode);

}
.....
....
private void Calendar_SelectionChanged(object sender, System.EventArgs e)
{
	ShowDailyEvents();
	Jump("calendar.aspx#bottom");
}
</code>
no luck.
I have also tried to use the 'focus' method like this:
I put an <a href="test" name="testme" id="testme">Test</a> in my aspx 
page, and in my code behind page I have the following: 

<code>
private void Jump(string id)
      {
string NewCode = "<script language=javascript>function Jump()" 
+ "document."   + id + ".focus()</script>";
Response.Write(NewCode);
    }
....
private void Calendar_SelectionChanged(object sender, System.EventArgs e)
      {
	ShowDailyEvents();
	Jump("testme");
       }
</code>


None of these methods work. I don't get an error, but it jumps to the top 
of the page as usual. 
what am i doing wrong ?? 
thanks for any help !!
Message #2 by "Van Knowles" <vknowles@s...> on Thu, 20 Feb 2003 21:05:52
I think what you need is this:

private void Jump(string url)
{

string NewCode = "<SCRIPT LANGUAGE = JavaScript>" 
+ "window.location = '" + url + "';</SCRIPT>";

Response.Write(NewCode);

}

--- or ---

private void Jump(string url)
{

string NewCode = "<SCRIPT LANGUAGE = JavaScript>" + "function jump()"
+ "{window.location = '" + url + "';} jump(); </SCRIPT>";

Response.Write(NewCode);

}

If you write a javascript _function_, it does not execute, it just sits 
there waiting for another script to execute it.

You have the choice of just writing naked javascript code which will 
execute outside of any function (first example) or writing the function 
and then executing it (second example).

If you're going to be doing much with javascript, you should check out the 
p2p javascript forums.

-Van
Message #3 by "dave" <dougwood@a...> on Fri, 21 Feb 2003 19:37:38
Great thanks Van,
I'll check it out!!

  Return to Index