I have the javascript function with parameter on the master page and all other pages are showing the result of that function on top of the screen. The problem, that I have - if I try to change the value of the parameter on the other page - it doesn't refresh
the value on the master page and consequent pages. Not sure if I am calling it correctly or missing something. On a
master page it is called with parameter value (default is 0)
The function to show the time is called on site.master with command:
<bodyonLoad="setInterval(startTime(), 1000);">
On the default page I call it with the parameter value 1 on page load - btnspanish.Attributes.Add("onclick", "startTime('1'); ");
I set Application["Spanish"] = 1 in btnspanish_click() function.
While debugging I discovered that once I click on btnspanish - it goes
to master page before the parameter is set to 1, therefore the command above on master page is called with 0, not 1 as I need. Then it goes back to default page and continues the steps from btnspanish_click function...
avascript with parameter on master page - call from default page
According to your description and codes, I couldn't understand your requirement clearly.
I find in your master page body onload method, you called setInterval method.
As far as I know, this method will always execute per second.
Do you mean you want to change this function in the content page?
Besides, I found this startTime function has no parameters in the body onload method.
<body onLoad="setInterval(startTime(), 1000);">
Why you could set the parameters in the content page?
Do you mean your page have two startTime function?
I suggest you could write a little demo about this error and post it.
If you could post more details information and codes, it will be more easily for us to find the solution.
Best Regards,
Brando
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
I had updated the code to call SetInterval with the parameter on master page load. Initially the parameter is 0 - which means that the default language is English and the function shows the date and time in English. The code is called on the
master page:
On the default page I have the button to switch the language and once user clicks on it - need to switch the date and time to show in Spanish. The problem that I am having - once user presses the button to switch
the language, the code goes to master page and calls RegisterStartupscript and calls it with Application["Spanish"]=0, not 1. I have the command setting it to 1 on default page on Click event, but the code goes to master page before it sets it to 1. How can
I fix it?
On default page load I tried to use attributes, but it's still not switching to Spanish...
The problem that I am having - once user presses the button to switch the language, the code goes to master page and calls RegisterStartupscript and calls it with Application["Spanish"]=0, not 1. I have the command setting it to 1 on default page on Click event,
but the code goes to master page before it sets it to 1. How can I fix it?
According to your description and codes, I couldn't see any coeds about how you set the Application["Spanish"].
I found in your master page's codes, if "Application["Spanish"] == null" the "Application["Spanish"]" is '0'.
So I think you don't set "Application["Spanish"]" to '1' well.
Could you please post the more relevant coeds about the button click event?
As far as I know, if you set the "Application["Spanish"]" to '1' in your button click event.
It will firstly execute the content page pageload event.
Then it will execute the master page pageload event.
At last it will execute the button click event.
Since I couldn't see the relevant codes about your master page and content page, I couldn't reproduce the issue you have faced.
I suggest you could use visual studio debugger tool to set a breakpoint to see how the codes works.
Besides, if you could post more relevant codes, it will be more easily for us to reproduce the problem and find the solution.
Best Regards,
Brando
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
When I debug and click on btnspanish - it goes to master page and runs the set time code with Application["Spanish"]=0, then comes back to btnspanish_Click and sets the parameter to 1, but keeps time in English, not Spanish. Sometimes I could see that it
flickers real fast to Spanish but reverses it back to English. Please advise on how to fix it.
The actual script with parameter:
<script type="text/javascript">
function startTime(flag_spanish) {
var today = new Date();
// debugger
if (flag_spanish == '1')
{
var days = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'];
var months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];
}
else
{
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
}
var mm = today.getMonth();
var dd = today.getDate();
var day = days[today.getDay()];
var yy = today.getFullYear();
var mnthdesc = months[today.getMonth()];;
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
var ampm;
if (h > 12)
{
h = h - 12;
ampm = "PM";
}
else
ampm = "AM";
m = checkTime(m);
s = checkTime(s);
document.getElementById("timevalue").innerHTML = day + " " + mnthdesc + " " + dd + ", " + yy + " " + h + ":" + m + " " + ampm;
var t = setTimeout(startTime, 500);
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
When I debug and click on btnspanish - it goes to master page and runs the set time code with Application["Spanish"]=0, then comes back to btnspanish_Click and sets the parameter to 1, but keeps time in English, not Spanish. Sometimes I could see that it flickers
real fast to Spanish but reverses it back to English. Please advise on how to fix it.
As my previous post says, the page's event execution order is like below:
If you click the button.
It will firstly execute the content page pageload event.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
I can see that the Application["Spanish"] is 1, yet it still shows text in English... I kept the other call on master page. What am I missing?
According to your javascript function codes, I find you reset the starttime again.
So it will still show the text in English.
More details, you could refer to follow codes:
function startTime(flag_spanish) {
var today = new Date();
// debugger
if (flag_spanish == '1')
{
var days = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'];
var months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];
}
else
{
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
}
var mm = today.getMonth();
var dd = today.getDate();
var day = days[today.getDay()];
var yy = today.getFullYear();
var mnthdesc = months[today.getMonth()];;
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
var ampm;
if (h > 12)
{
h = h - 12;
ampm = "PM";
}
else
ampm = "AM";
m = checkTime(m);
s = checkTime(s);
document.getElementById("timevalue").innerHTML = day + " " + mnthdesc + " " + dd + ", " + yy + " " + h + ":" + m + " " + ampm;
var t = setTimeout(startTime, 500);
}
Best Regards,
Brando
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Well, I'm at complete loss. If I remove that time reset command - it doesn't reset time, the date in Spanish or English is still not working correctly. I tried to use Cache instead of Application[".."] - same results.
I changed the code to reset it with the flag - the same issue, except now when I press Spanish - it shows time in English, when I press English - it shows time in Spanish. Seems like there is a delay in interpreting the flag.
var t = setTimeout(startTime(flag_spanish), 500);
I tried to change the flag from 0 to 2 - same results. Tried to reverse the numbers and call English flag on the button that triggers Spanish - it didn't work either! So that tells me that it ignores the calling of the startTime() and script register on
button click... What else can I try???
I tried to change the flag from 0 to 2 - same results. Tried to reverse the numbers and call English flag on the button that triggers Spanish - it didn't work either! So that tells me that it ignores the calling of the startTime() and script register on button
click... What else can I try???
According to your description, I couldn't reproduce the issue you faced now.
Could you please post more relevant codes or a little demo about your codes now?
I will test it and reproduce the issue you faced now.
Like below:
Master Page:
....
Code-behind:
.....
Content Page:
....
Content page code-behind:
....
Best Regards,
Brando
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
I changed the code to reset it with the flag - the same issue, except now when I press Spanish - it shows time in English, when I press English - it shows time in Spanish. Seems like there is a delay in interpreting the flag.
According to your description and codes, I have written a test demo on my computer.
Since I don't have inint method and couldn't see your html makeup, I change a little code, it works well.
I think your just want to change the language in your page.
So I suggest you could refer to follow codes:
Master Page JS:
<script type="text/javascript">
var temp;
function startTime(flag_spanish) {
temp = flag_spanish;
var today = new Date();
// debugger
if (flag_spanish == '1')
{
var days = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'];
var months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];
}
if (flag_spanish == '0')
{
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
}
var mm = today.getMonth();
var dd = today.getDate();
var day = days[today.getDay()];
var yy = today.getFullYear();
var mnthdesc = months[today.getMonth()];;
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
var ampm;
if (h > 12)
{
h = h - 12;
ampm = "PM";
}
else
ampm = "AM";
m = checkTime(m);
s = checkTime(s);
//document.getElementById("timevalue").innerHTML = h + ":" + m + ":" + s + " " + ampm;
document.getElementById("timevalue").innerHTML = day + " " + mnthdesc + " " + dd + ", " + yy + " " + h + ":" + m + " " + s + " " + ampm;
//document.getElementById("dayvalue").innerHTML = day;
//document.getElementById("monthvalue").innerHTML = mnthdesc;
//document.getElementById("daynumvalue").innerHTML = dd;
//document.getElementById("yearvalue").innerHTML = yy;
//document.getElementById("timedatev").innerHTML = day1;
// debugger
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
window.onload = function() {
if (temp == null) {
temp = 0;
}
//refresh page
setInterval(function () { startTime(temp);}, 1000);
};
</script>
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
9 Points
94 Posts
javascript with parameter on master page - call from default page
Oct 28, 2016 07:50 PM|asanders2552|LINK
Hello
I have the javascript function with parameter on the master page and all other pages are showing the result of that function on top of the screen. The problem, that I have - if I try to change the value of the parameter on the other page - it doesn't refresh the value on the master page and consequent pages. Not sure if I am calling it correctly or missing something. On a master page it is called with parameter value (default is 0)
The function to show the time is called on site.master with command:
On the default page I call it with the parameter value 1 on page load - btnspanish.Attributes.Add("onclick", "startTime('1'); ");
I set Application["Spanish"] = 1 in btnspanish_click() function.
While debugging I discovered that once I click on btnspanish - it goes to master page before the parameter is set to 1, therefore the command above on master page is called with 0, not 1 as I need. Then it goes back to default page and continues the steps from btnspanish_click function...
Please advise on how I can fix it. Thanks!
Star
9831 Points
3120 Posts
Re: javascript with parameter on master page - call from default page
Oct 31, 2016 05:56 AM|Brando ZWZ|LINK
Hi asanders2552,
According to your description and codes, I couldn't understand your requirement clearly.
I find in your master page body onload method, you called setInterval method.
As far as I know, this method will always execute per second.
Do you mean you want to change this function in the content page?
Besides, I found this startTime function has no parameters in the body onload method.
Why you could set the parameters in the content page?
Do you mean your page have two startTime function?
I suggest you could write a little demo about this error and post it.
If you could post more details information and codes, it will be more easily for us to find the solution.
Best Regards,
Brando
Member
9 Points
94 Posts
Re: javascript with parameter on master page - call from default page
Oct 31, 2016 12:54 PM|asanders2552|LINK
Hello again
I had updated the code to call SetInterval with the parameter on master page load. Initially the parameter is 0 - which means that the default language is English and the function shows the date and time in English. The code is called on the master page:
On the default page I have the button to switch the language and once user clicks on it - need to switch the date and time to show in Spanish. The problem that I am having - once user presses the button to switch the language, the code goes to master page and calls RegisterStartupscript and calls it with Application["Spanish"]=0, not 1. I have the command setting it to 1 on default page on Click event, but the code goes to master page before it sets it to 1. How can I fix it?
On default page load I tried to use attributes, but it's still not switching to Spanish...
Star
9831 Points
3120 Posts
Re: javascript with parameter on master page - call from default page
Nov 02, 2016 07:53 AM|Brando ZWZ|LINK
Hi asanders2552,
According to your description and codes, I couldn't see any coeds about how you set the Application["Spanish"].
I found in your master page's codes, if "Application["Spanish"] == null" the "Application["Spanish"]" is '0'.
So I think you don't set "Application["Spanish"]" to '1' well.
Could you please post the more relevant coeds about the button click event?
As far as I know, if you set the "Application["Spanish"]" to '1' in your button click event.
It will firstly execute the content page pageload event.
Then it will execute the master page pageload event.
At last it will execute the button click event.
Since I couldn't see the relevant codes about your master page and content page, I couldn't reproduce the issue you have faced.
I suggest you could use visual studio debugger tool to set a breakpoint to see how the codes works.
Besides, if you could post more relevant codes, it will be more easily for us to reproduce the problem and find the solution.
Best Regards,
Brando
Member
9 Points
94 Posts
Re: javascript with parameter on master page - call from default page
Nov 02, 2016 12:09 PM|asanders2552|LINK
I set the Application["Spanish"] on the button click on the default page.
Just to recap. On master page load:
On default page:
On default page on btnspanish click:
When I debug and click on btnspanish - it goes to master page and runs the set time code with Application["Spanish"]=0, then comes back to btnspanish_Click and sets the parameter to 1, but keeps time in English, not Spanish. Sometimes I could see that it flickers real fast to Spanish but reverses it back to English. Please advise on how to fix it.
The actual script with parameter:
Star
9831 Points
3120 Posts
Re: javascript with parameter on master page - call from default page
Nov 06, 2016 08:31 AM|Brando ZWZ|LINK
Hi asanders2552,
As my previous post says, the page's event execution order is like below:
If you click the button.
It will firstly execute the content page pageload event.
This codes:
Then it will execute the master page pageload event.
At last it will execute the button click event.
So you will find it doesn't changed.
I suggest you could try to call RegisterStartupScript method and content page load in button click event.
More details, you could refer to follow codes:
Best Regards,
Brando
Member
9 Points
94 Posts
Re: javascript with parameter on master page - call from default page
Nov 07, 2016 03:01 PM|asanders2552|LINK
Per your suggestion - added this command on the button click-
I can see that the Application["Spanish"] is 1, yet it still shows text in English... I kept the other call on master page. What am I missing?
Star
9831 Points
3120 Posts
Re: javascript with parameter on master page - call from default page
Nov 09, 2016 01:26 PM|Brando ZWZ|LINK
Hi asanders2552,
According to your javascript function codes, I find you reset the starttime again.
So it will still show the text in English.
More details, you could refer to follow codes:
function startTime(flag_spanish) { var today = new Date(); // debugger if (flag_spanish == '1') { var days = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado']; var months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']; } else { var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; } var mm = today.getMonth(); var dd = today.getDate(); var day = days[today.getDay()]; var yy = today.getFullYear(); var mnthdesc = months[today.getMonth()];; var h = today.getHours(); var m = today.getMinutes(); var s = today.getSeconds(); var ampm; if (h > 12) { h = h - 12; ampm = "PM"; } else ampm = "AM"; m = checkTime(m); s = checkTime(s); document.getElementById("timevalue").innerHTML = day + " " + mnthdesc + " " + dd + ", " + yy + " " + h + ":" + m + " " + ampm; var t = setTimeout(startTime, 500); }
Best Regards,
Brando
Member
9 Points
94 Posts
Re: javascript with parameter on master page - call from default page
Nov 09, 2016 09:19 PM|asanders2552|LINK
Well, I'm at complete loss. If I remove that time reset command - it doesn't reset time, the date in Spanish or English is still not working correctly. I tried to use Cache instead of Application[".."] - same results.
I changed the code to reset it with the flag - the same issue, except now when I press Spanish - it shows time in English, when I press English - it shows time in Spanish. Seems like there is a delay in interpreting the flag.
var t = setTimeout(startTime(flag_spanish), 500);
I tried to change the flag from 0 to 2 - same results. Tried to reverse the numbers and call English flag on the button that triggers Spanish - it didn't work either! So that tells me that it ignores the calling of the startTime() and script register on button click... What else can I try???
Star
9831 Points
3120 Posts
Re: javascript with parameter on master page - call from default page
Nov 10, 2016 01:40 AM|Brando ZWZ|LINK
Hi asanders2552,
According to your description, I couldn't reproduce the issue you faced now.
Could you please post more relevant codes or a little demo about your codes now?
I will test it and reproduce the issue you faced now.
Like below:
Master Page:
....
Code-behind:
.....
Content Page:
....
Content page code-behind:
....
Best Regards,
Brando
Member
9 Points
94 Posts
Re: javascript with parameter on master page - call from default page
Nov 10, 2016 10:22 PM|asanders2552|LINK
Master page:
Default page:
I appreciate your help!!!
Star
9831 Points
3120 Posts
Re: javascript with parameter on master page - call from default page
Nov 16, 2016 03:09 AM|Brando ZWZ|LINK
Hi asanders2552,
According to your description and codes, I have written a test demo on my computer.
Since I don't have inint method and couldn't see your html makeup, I change a little code, it works well.
I think your just want to change the language in your page.
So I suggest you could refer to follow codes:
Master Page JS:
Page load event:
Conent page button click event:
Result:
Best Regards,
Brando