Please let me ask something. I just confused for what is the difference of javascript, JQuery and code behind attributes.
for example :
ASPX
<tbody id="toggleSup" runat="server">
C#
toggleSup.Visible = false;
————————————— OR —————————
C#
CallScript((string)(Session["toggle"]));
private void CallScript(string str)
{
string scriptx = "<SCRIPT LANGUAGE='javascript'>";
scriptx += "toggle('" + str + "');";
scriptx += "</script>";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "scriptx", scriptx, false);
}
Script
function toggle(para1) {
if (para1 == 0) {
$('#toggleSup').hide();
}
else {
$('#togglePO').hide();
}
}
for these two difference things, most of the developers use script. Why? Actually C# code is only one row. different thing is if I use script, no need to use runat=”server” but if I used code behind, need to use runat = “server”. So I think there may be definately have advantages. Please explain me, if possible…
Thanks
If you say
toggleSup.Visible = false;in your C#, then the toggleSup does not even get rendered to the DOM. Meaning it’s not on the page at all. If you want to make that element visible from some action on the page, then you have to make a round trip to the server and re-render all (postback) or part (ajax) of the page.Alternatively, if you allow the
toggleSubcontrol to be manipulated from JavaScript (jQuery in this case), then it’s part of the DOM and can be acted upon in response to other events on the page. Mainly, this means that the client browser can do things without asking the server for more HTML.So, the C# method looks simpler to code, but the jQuery method is more flexible if you need a rich client-side experience.