some tips of javascript..

1.How to open a new Window using javascript function from a Link button?
link.Attributes[ "onClick" ] = "window.open( 'url', 'name', 'properties' )";

2.How to get the confirmation of Yes/No from a javascript pop-up and display the value on the page?
ans :
Code Behind


Button1.Attributes.Add("onclick", "getMessage()");
script at Client Side
<SCRIPT language=javascript>
function getMessage()
{
var ans;
ans=window.confirm('Is it your confirmation.....?');

if (ans==true)
{
alert("yes");
}
else
{
alert("no");
}
</SCRIPT>

3. How to open a browser window with maximum size on click of a button?
Button1.Attributes.Add("onclick", "window.open('page2.aspx','','fullscreen=yes')");

4.How to determine if the Browser supports javascript?

if (Page.Request.Browser.JavaScript )
{
...
}
else
{
...
}

5.How can I use a Timer Control to refresh a page automatically at a specified interval?

<asp:DropDownList id="DropDownList1" runat="server" onChange="SetClientRefresh(this);">
<asp:ListItem Value="1000">1 second</asp:ListItem>
<asp:ListItem Value="2000">2 seconds</asp:ListItem>
<asp:ListItem Value="3000">3 seconds</asp:ListItem>
</asp:DropDownList>
<script language='javascript'>
var cTimeOut = null;
function SetClientRefresh(sel)
{
var newRefresh = sel.options[sel.selectedIndex].value;
if (cTimeOut != null)
{
window.clearTimeout(cTimeOut);
}
cTimeOut = window.setTimeout("ReLoadPage()", newRefresh);
}

function ReLoadPage()
{
window.location.reload();
}
</script>


6.How to change a Label element's text in javascript?
document.getElementById("Label1").innerText = "Changed Text";


7.How to check/ uncheck a checkbox based on the text entered in textbox?

<script type="text/javascript">
function chkTextEntered()
{
document.getElementById("CheckBox1").checked = true;
if(document.getElementById("TextBox1").value =="" )
{
document.getElementById("CheckBox1").checked = false;
}
}
</script>

TextBox1.Attributes.Add("onKeyDown", "chkTextEntered();");


8.How to change the BackGroundColor of a page based on the value selected in a DropdownList?

<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
</asp:DropDownList>
Page.RegisterClientScriptBlock("BodyStyle", "<style type='text/css'>body{background-color: " + DropDownList1.SelectedItem.Value + ";}</style>");


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: