Tag: javascript

JavaScript Expand Collapse

[+] Main Item


Javascript Onload event for Default pages with Master Pages

I have an asp.net website and I have created a default page (Default.aspx) with MasterPage. Like this i have created many pages (.aspx) with the same MasterPage.

Now i want to write a javascript body onload event only to Default.aspx. How can i do this? because body tag is in master page. but i want to use it only to Default.aspx.

in the cs file put following line
ClientScript.RegisterStartupScript(ClientScript.GetType(), “onLoad”, “fnTest()”, true);

In aspx file put following line


Call Server Side methods from JavaScript

Some times we need to call server side function from Javascript function.For example,callig a PoupWindow(with value from code behind) on HyperLink click.

This must be implemented by creating a additional request to the web server and that’s the only way to invoke methods on the server. Page methods are used for this.

What is PageMethod?

A PageMethod is a public static method that is exposed in the code-behind of a page and can be called from the client script. PageMethods are annotated with [System.Web.Services.WebMethod] attribute.

The code is simple..

Server side function


CSS, JavaScript from Code Behind

CSS from Code Behind

gv_Unassigned.Rows(gv_Unassigned.SelectedIndex).Style(“Color”) = “White”

Me.div12.Style(“overflow-x”) = “hidden”

JavaScript From Code Behind

Response.Write(“<script>”)

Response.Write(“window.open(‘” & TrackUrl & “‘,’_blank’);”)

Response.Write(“</script>”)


JavaScript..Print contents in a DIV

PRINT WATEVER YOU WANT IN A DIV, ON A BUTTON CLICK.

Aaron says “Create a div around the content you want to print”.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

ButtonPrint.Attributes.Add(“onclick”, “javascript:CallPrint(‘divPrint’);”)
end sub

<script language=”javascript”>
function CallPrint(strid) {
var prtContent = document.getElementById(strid);
var strOldOne = prtContent.innerHTML;
var WinPrint = window.open(”, ”, ‘left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0′);
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML = strOldOne;
}
</script>

Strid should be the ID of the DIV.

Dont forget runat=”Server”


  • Cloud World

  • Custom Search



  • Cyberbrutus
    iDream theme by Templates Next | Powered by WordPress

    Switch to our mobile site