Why ASP.NET Master Page Name Mangling is important? I did not know about it before I encounter some issue with JavaScript ID naming. I cannot run the JavaScript code due to wrong ID name.
For example, you create a button with ‘Button1′ as its ID. Its name will still be ‘Button1′ under normal HTML. However, its name changes if you use ASP.NET MasterPage. It will change to ‘ctl00$Button1′ from ‘Button1′. You can find that out when you see its source code using Internet Explorer / Firefox view source function.
Here are some source code to pass DateTime JavaScript value to ASP.NET in C#. It is used to get client side date and time. It is useful for those who need to display client date and time instead of hosting server date and time.
Put these codes at HTML
<input type=”hidden” id=”hdClient” runat=”server” />
Put these codes at ASP.NET code behind
At Page_Load
Page.RegisterClientScriptBlock(”1″,
“<script type=’text/javascript’>
function goforit()
{var now = new Date();
var offset = now.getTimezoneOffset();
document.forms[0].hdClient.value = -offset}
</script>”);ClientScriptManager manager = Page.ClientScript;
manager.RegisterStartupScript(this.GetType(), “CallSomething”, “goforit();”, true);
And…
Label1.Text =
DateTime.Now.ToUniversalTime().AddMinutes(double.Parse(Request.Form[”hdClient”])).ToString();
Hope this will help. ![]()