I am facing an issue with the response.redirect command in my webmethod call. Here is a snippet of my code:
HTML:
<a onclick="proximaAula()">Next Lesson -></a>
JS:
function proximaAula() {
var tipo = getParameterByName('t');
if (tipo == "1") {
//PageMethods.MyMethod(projekktor('player_a').getPosition(), projekktor('player_a').getDuration(), getParameterByName('codaula'));
PageMethods.NextAula(projekktor('player_a').getPosition(), projekktor('player_a').getDuration(), getParameterByName('codaula'));
}
//alert(tipo);
if (tipo == "3") {
var iframe = document.getElementById('viewer');
var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
var pag;
var npag;
if (iframeDocument) {
elem = iframeDocument.getElementById('pageNumber').value;
npag = iframeDocument.getElementById('numPages').innerHTML;
npag = npag.substring(3, npag.length);
}
//return "asasdas"; //
//alert(elem + " - " + npag);
PageMethods.NextAula(elem,npag,getParameterByName('codaula'));
}
if (tipo == "4") {
PageMethods.NextAula("-1","-1",getParameterByName('codaula'));
}
}
C#:
[WebMethod]
public static string NextAula(string tempo, string tempomax, string codaula)
{
escolawebEntities DB = new escolawebEntities();
string link = "";
int icodaula = int.Parse(codaula);
eadaulaaluno eaula = (from x in DB.eadaulaaluno where x.codeadaula == icodaula select x).FirstOrDefault();
tempo = tempo.Substring(0, tempo.IndexOf('.'));
tempomax = tempomax.Substring(0, tempomax.IndexOf('.'));
int ntempo = ((int.Parse(tempo) * 100) / int.Parse(tempomax));
if (tempo == tempomax || eaula.percentual == eaula.percentualmax || ntempo >= 95 )//ou perc ser maior 98%
{
eadaula aaula = (from x in DB.eadaula where x.eadcodaula == icodaula select x).FirstOrDefault();
eadaula paula = (from x in DB.eadaula
where x.eadcodcursomodulo == aaula.eadcodcursomodulo
where x.ordem == aaula.ordem + 1
select x).FirstOrDefault();
if (paula != null)
{
//link = "eadVerAula.aspx?codaula=" + paula.eadcodaula + "&t=" + paula.eadcodmidia;
HttpContext.Current.Response.Redirect("eadVerAula.aspx?codaula=" + paula.eadcodaula + "&t=" + paula.eadcodmidia,false);
//Context.Response.StatusCode = 307;
//Context.Response.AddHeader("Location", "<redirect URL>");
// HttpContext.Current.Response.StatusCode = 307;
// HttpContext.Current.Response.AddHeader("Location", "eadVerAula.aspx?codaula=" + paula.eadcodaula + "&t=" + paula.eadcodmidia);
}
//HttpContext.Current.Response.Redirect("eadVerAula.aspx?codaula=" + paula.eadcodaula + "&t=" + paula.eadcodmidia);
//link = "eadVerAula.aspx?codaula=" + paula.eadcodaula + "&t=" + paula.eadcodmidia;
}
return "";
}
I have tried different methods to redirect the page but faced challenges. This code functionality involves clicking a link that triggers a JavaScript function to send information to the server using a webmethod.