Hjælp med JavaScript i asp.net 2.0
Hej E.Jeg har store problemer med at få et javascript til at virker i en .aspx fil.
Hvis jeg includere scriptet i en html side på den gamle måde, så virker det som det skal.
Det er kun i min .aspx side der er problemer.
HVORDAN GÅR MAN I ASP.NET 2.0??
Via Google har jeg fundet ud at, at man skal registrere javascriptet i page objektet. Kan det være rigtigt?
Dette gør jeg på følgende måde.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Define the name, type and url of the client script on the page.
Dim csname As String = "AdminScrollScript"
Dim csurl As String = "~/Scroll.js"
Dim cstype As Type = Me.GetType()
' Get a ClientScriptManager reference from the Page class.
Dim cs As ClientScriptManager = Page.ClientScript
' Check to see if the include script is already registered.
If (Not cs.IsClientScriptIncludeRegistered(cstype, csname)) Then
cs.RegisterClientScriptInclude(cstype, csname, ResolveClientUrl(csurl))
End If
End Sub
Men når jeg gør det, så går min side i stykker. Der kommer ikke en fejl, siden hænger bare.
Mit javascript er her:
<!--
/* MCPosition:absolute layer */
/* Script by Marc Clemmensen */
/* http://exp.dk/spm/715114 */
/* - - - Version: 0.97 - - - */
/* Free use - keep this note */
/* If changed add extra note */
/* Edited version by MClemens */
/* Changeable values */
mcpcs=10; // Speed of animation in ms.
mcpcp=2; // Amount of pixels used for each change.
mcperr=false; // Alert if missing a div in document (true/false)
/* ----------------- */
/* Don't touch script below unless you know where to edit */
var mcp={}; // Object for transportation of objects and their properties
window.onload=function(){
// Initiate element gathering onload
var tns=document.getElementById("mcp_div").childNodes; // Get all childs
while(tns.length>0){
if(tns[0].id){
// Check if you've made all div's neccessary...
if(tn=document.getElementById(tns[0].id+"_")){
mcp[tns[0].id]={
c:false,r:0, // Set open/close check and running count
o:tns[0],s:tns[0].style, // Shortcut to object and style
h:tns[0].offsetHeight,w:tns[0].offsetWidth // Store elements initial width and height
};
tns[0].style.top=-tns[0].offsetHeight+"px"; // Position div at top
tn.style.height="0px"; // Set height of new parent div element
tn.style.width=tns[0].offsetWidth+"px"; // Set width of new parent div element
tn.removeChild(tn.childNodes[0]);tn.appendChild(tns[0]); // Move div element
}else if(mcperr)alert("The div with id:\n"+tns[0].id+"_\n- was not found");
}
else{
tnx=document.getElementById("mcp_div");
tnx.removeChild(tnx.childNodes[0]);
}
}
}
function mcppos(mcp0,mcp1){
mcp0=mcp["mcp"+mcp0]; // Activate shortcut
mcp2=++mcp0.r; // Get timeout run number
if(mcp1==3)mcp0.c=!mcp0.c; // Make a check value for the action
else mcp0.c=(mcp1==1)?true:false;
setTimeout("mcpact('"+mcp0.o.id+"',"+mcp2+");",2*mcpcs); // Activate layer handling
}
function mcpact(mcp0,mcp2){
mcp0=mcp[mcp0]; // Activate shortcut
if(mcp2==mcp0.r){ // Check if this is the active layer timeout
tmpns=mcp0.o.offsetParent.style;
tmpnsh=parseInt(tmpns.height.replace("px","")); // Get parent current height
tmpval=(mcp0.c)?mcpcp:-tmpnsh; // Tmp value for offsetting
tmperr=false;
if((tmpnsh+tmpval)>mcp0.h)tmpval=mcp0.h-tmpnsh; // Don't make div above actual height
else if((tmpnsh+tmpval)<0)tmpval=-tmpnsh; // Don't make div below 0px height
else tmperr=true;
tmpns.height=tmpval+tmpnsh+"px"; // Set new height
mcp0.s.top=-mcp0.h+tmpval+tmpnsh+"px"; // Set top
if(tmperr)setTimeout("mcpact('"+mcp0.o.id+"',"+mcp2+");",mcpcs);
}
}
// -->