Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

window.open method

Posted by Venkat | Labels: , ,

Window.open method in asp.net - this is used in javascript to open a page on new window.
through this you can hide the menubar ,set the width and hieght of the popupwindow,status,toolbar,resizable etc., for this you can either set the value is 0 | 1 or yes | no

Example

window.open('http://msdn.microsoft.com', '', '');");

Suppose if you want to do on code behind check this code :

Here i have mentioned widht , height of the window ,top and left , menubar,toolbar,
location, resizable, scrollbars
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script language="javascript">");
sb.Append("window.open('popuop.aspx', 'CustomPopUp',");
sb.Append("'width=1020, height=750, left=0, top=0, menubar=no, toolbar=no, resizable=no, status=no, location=no, scrollbars=yes');<");
sb.Append("/script>");
Type t = this.GetType();
if (!Page.ClientScript.IsStartupScriptRegistered(t, "PopupScript"))
{
     Page.ClientScript.RegisterStartupScript(t, "PopupScript", sb.ToString());
 }


If you want to open a new window through in-line code try this.

   <img border="0" id="img_PopUp" onclick="window.open('../PopUp.aspx','custompopop','width=250,height=300,toolbar=no,menubar=no,statusbar=no,resizable=no,scrollbars=no,location=no, directories=no,copyhistory=no,left=250,top=250')" />
                                runat="server" src="../Images/Newwindow.png" style="width: 35px" />

Reference:


http://dotnetslackers.com/articles/aspnet/JavaScript_with_ASP_NET_2_0_Pages_Part1.aspx

Creation Tooltip

Posted by Venkat | Labels: , ,

Good Friday to all.

Now i am going to show how to create  a Tooltip using Javascript there are many scripts,JQuery available to make the work easy and even we can design the tooltip stylish manner.

But finally i have worked with this sample , it shows tooltip , when u click on the Textbox - you can give your own font color, backcolor.

Here is the link Check it

http://lixlpixel.org/javascript-tooltips/

And its a dynamic tool tip..

http://blog.devarchive.net/2008/04/advanced-tooltip-control-aspnet-ajax.html

Here is the Screenshot

How to Create Nifty Round corner

Posted by Venkat | Labels: , ,

I have situation Create a Roundcorner for the table or div or panel ...
So in Ajax there is a built-in-control - RoundCornerExtender is available , but i have used that but i was not showing the round corner sometimes properly.

so i found this Nifty round corner was the good one, no image needed for the Round Corner.

Its full javascript., you can apply the round corner to div,panel,table etc..

Here is the Sample code

First you have to add Javascript on your page. You can get the javascript here ie: niftycube.js and niftycorner.css.

http://www.html.it/articoli/nifty/index.html

http://www.html.it/articoli/niftycube/index.html

You have to write code like this

if you use id use (#) , if you are going to use it for class user (.)


<script type="text/javascript">
window.onload=function(){
Nifty("div#box","big");
Nifty("Panel#" + '<%= contactUs_Panel.ClientID %>',"transparent");
Nifty("Panel.setround","big");
Nifty("Panel#" + '<%= callback_Panel.ClientID %>',"transparent");
Nifty("table.setround","big");

//Nifty("PopupControlExtender","big");
}
</script>


Visible the Textbox when User Select Others on the Dropdownlist using Javascript

Posted by Venkat | Labels: ,

Hi i have came across one task, ie: I have dropdownlist that has some items along with 'Others' So if the user Choose the value Others -  i have to visible the Textbox and Validator so user should enter somthing on the textbox else it show Validation error if the user choose any other item , i have to disable the Textbox and the Validator.

Using Javascript its easy to do this , i am not good in Javascript i got a help from the Expert to make it work.

ASPX

<asp:DropDownList ID="EducationLevel_DropDownList" runat="server" Width="202px"
                                            Font-Names="Verdana" Font-Size="10pt" AppendDataBoundItems="True">
                                            <asp:ListItem Value="-1">Select</asp:ListItem>
                                            <asp:ListItem Value="1">PhD</asp:ListItem>
                                            <asp:ListItem Value="2">PhD Student</asp:ListItem>
                                            <asp:ListItem Value="3">Master Degree</asp:ListItem>
                                            <asp:ListItem Value="4">Bachelor Degree</asp:ListItem>
                                            <asp:ListItem Value="5">Under Graduate Student</asp:ListItem>
                                            <asp:ListItem Value="6">Others</asp:ListItem>
                                        </asp:DropDownList>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="EducationLevel_DropDownList"
                                            Display="Dynamic" ErrorMessage="Education Leve required !" InitialValue="-1"
                                            SetFocusOnError="True" ValidationGroup="Profile" Font-Size="8pt">*</asp:RequiredFieldValidator><asp:TextBox ID="TextBox1"
                                                runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
                                            Display="Dynamic" ErrorMessage="Education Leve required !" 
                                            SetFocusOnError="True" ValidationGroup="Profile" Font-Size="8pt">*</asp:RequiredFieldValidator>

And the Javascript is given below so here i am pass the Valuefield of Other ie: 6 , when a textbox has validators, they are stored in the Validators collection , so no need to pass the ValidatorID.


JAVASCRIPT


<script type="text/javascript" language ="javascript" >


function getSelectValue(sel) {
   
    var val;
    // only if there is a selected item
    if (sel.selectedIndex>-1) {
        // get the value from the select element
        val=sel.options[sel.selectedIndex].value;
       // alert(val);
    }
   
    return val;
}


        function ddlChange(DropDownID,TextBoxID)
        {
            var c=document.getElementById(DropDownID);
            var div=document.getElementById(TextBoxID);
            if(getSelectValue(c)=='6')
            {
                div.value='';
                div.style.visibility="visible";
                if (div.Validators&&div.Validators.length) {
                   for (var i=0; i<div.Validators.length; i++)
                       ValidatorEnable(div.Validators[i], true)
                }
            }
            else
            {
                div.value='6';
                div.style.visibility="hidden";
                if (div.Validators&&div.Validators.length) {
                   for (var i=0; i<div.Validators.length; i++)
                       ValidatorEnable(div.Validators[i], false)
                }
            }
        }
    </script>

Then On_PageLoad you have to pass the TextboxID and DropdownlistID to the Javascript Function.


EducationLevel_DropDownList.Attributes.Add("onchange", "ddlChange('" + EducationLevel_DropDownList.ClientID + "','" + TextBox1.ClientID + "');");
        TextBox1.Style.Add("visibility", "hidden");

Refresh the Parent Page after Closing PopUp Page (window)

Posted by Venkat | Labels: ,

Good Day to all

And also I wish you a Very Happy FriendShip Day..

Now we have to discuss the How to Refresh the parent window by Closing the popup window

Passing the function on your button ie: place Close button on you popup If you click the Close Button , it will close the popup and refresh the parent page.


<script>
function refreshParent() {
window.opener.location.href = window.opener.location.href;

if (window.opener.progressWindow)

{
window.opener.progressWindow.close()
}
window.close();

}
</script>

Watermark the textbox using javascript

Posted by Venkat | Labels: ,

Hi , Now we have to discuss about the watermark the textbox using javascript

for that you have to use onblur and onfocus property of your textbox


<script type = "text/javascript">

var defaultText = "Enter your text here";

function WaterMark(txt, evt)

{

if(txt.value.length == 0 && evt.type == "blur")

{

txt.style.color = "gray";

txt.value = defaultText;

}

if(txt.value == defaultText && evt.type == "focus")

{

txt.style.color = "black";

txt.value="";

}

}

</script>


Here is the HTML Code of the Textbox control

<asp:TextBox ID="TextBox1" runat="server" Text = "Enter your text here"

ForeColor = "Gray" onblur = "WaterMark(this, event);"

onfocus = "WaterMark(this, event);">

</asp:TextBox>

Now we have to write the attributes through code on your Page_load Event

TextBox1.Attributes.Add("onblur", "WaterMark(this, event);")

TextBox1.Attributes.Add("onfocus", "WaterMark(this, event);")

How to Detect the user Close the page

Posted by Venkat | Labels:

You can use the onunload or the onbeforeunload events to execute codes when the browser is about to closed.

You may also use Page Methods, see below

http://aspalliance.com/1294_CodeSnip_Handle_Browser_Close_Event_on_the_ServerSide.all

The code below will simulates the closed button of the browser when the user invoked the button and display an alert message..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function doSomething()
{
alert('Widnow is about to close');
}
</script>

</head>
<body onunload="doSomething();">
<form id="form1" runat="server">

</form>
</body&gt;

PayOffers.in