Saturday, March 24, 2012

how to get selected item from dropdownlist in javascript

var ddl=document.getElementById ("<%=DropDownList1.ClientID%>");
var text=ddl.options[ddl.selectedIndex].text;

Friday, March 23, 2012

how to add remove items in dropdown list in java script

how to add remove items in dropdown list in java script in

it is very easy to add and remove items in javascript .

Here is the code for it...

<script type="text/javascript">
    function AddItem(Text,Value)
        // Create an Option object for adding item to dropdownlist       
        var opt = document.createElement("option");

        // Add an Option object to Drop Down/List Box
        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;

    }<script />

Enjoyyyy Programming..

Thursday, March 22, 2012

Call JavaScript function from code behind in

It is very easy to call javascript function from code behind .

In .cs code write

  string url = "yourpage.aspx?ManiFestNumber=" + value;
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "rates", "openWindow('" + url + "');", true);                  

in aspx page just write in this code 

<script type="text/javascript">

    function openWindow(url)
    var w =, '', 'width=1,height=1,toolbar=0,status=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0');

and Its done .........

Tuesday, March 6, 2012

Compare Validator for performing date validation

<asp:CompareValidator ID="CompareValidatorBookingDeadline" runat="server"
ControlToValidate="TextBoxExpiaryDate" Display="Dynamic"
ErrorMessage="Please check the date."
ValueToCompare="<%= TextBoxSeminarDate.Text.ToShortString() %>">*</asp:CompareValidator>
The important thing is "ValueToCompare" property of the compare validator.

Saturday, March 3, 2012

Getting selected value from drop down using java script in

<asp:DropDownList ID="dropDown" runat="Server">

                                        <asp:ListItem Text="Item 1" Value="1" Selected="True"></asp:ListItem>

                                        <asp:ListItem Text="Item 2" Value="2"></asp:ListItem>

                                        <asp:ListItem Text="Item 3" Value="3"></asp:ListItem>




                                    <input type="button" value="Submit" onclick="GetDropDownValue('<%= dropDown.ClientID %>')" />

// Get DropDown value function GetDropDownValue(id) { alert(document.getElementById(id).value); }