Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have member id text box and member drop down with name and ID

i have a fuctionality that when after binging dropdpwn i need to call dropdown_selected change event.

in same way when user enter member id in text box i need fire text box change event to check wherther ,drop down contains that value(ID) or not.
Posted

1 solution

There is a TextBox1_TextChanged event for this.
XML
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" ontextchanged="TextBox1_TextChanged"></asp:TextBox>

C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    //do something.
}


This will let the page post back and the code will be executed on the server.

If you do not need server side processing, using JavaScript is recommended.
You can add an onblur event to the textbox and call a JavaScript function to do the required validation.
XML
<asp:TextBox ID="TextBox1" runat="server" onblur="return ValidateDDL();"></asp:TextBox>

C#
function ValidateDDL()
{
    if(document.getElementById("<%= DropDownList1.ClientID %>").value == document.getElementById("<%= TextBox1.ClientID %>").value)
    {
        alert("cannot be duplicate");
        return false;
    }
    return true;
}


Hope this helps!
 
Share this answer
 
Comments
Ankur\m/ 9-May-11 9:22am    
And yes, get a good beginner book for ASP.NET and invest some time studying the basic (or read the beginner articles on CP and web). It will help you in the long run. :thumbsup:
Sandeep Mewara 9-May-11 11:02am    
5!
Ankur\m/ 10-May-11 0:04am    
Thanks you, Sir. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900