Pages

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;
alert(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 asp.net


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
        document.getElementById("DropDownList").options.add(opt);
        // 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 asp.net

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


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 = window.open(url, '', 'width=1,height=1,toolbar=0,status=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0');
    w.focus();
}





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

Tuesday, March 6, 2012

Compare Validator for performing date validation


<asp:CompareValidator ID="CompareValidatorBookingDeadline" runat="server"
ControlToCompare="TextBoxTodayDate"
ControlToValidate="TextBoxExpiaryDate" Display="Dynamic"
ErrorMessage="Please check the date."
Operator="LessThanEqual"
Type="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.net



<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>

                                    </asp:DropDownList>

                                </td>

                                <td>

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




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