当前位置: 动力学知识库 > 问答 > 编程问答 >

How to add two ajax extenders on same control in asp.net

问题描述:

I have a dropdownlist and a textbox. there are 2 listitem in dropdownlist one is name and other is date. I added autocomplete extender and calender control extender on textbox.

Because after selecting value from dropdownlist user have to write in textbox. I want when user select name autocomplete extender work and when user select date then on click in texttbox a Calender is appear(ie, calender extender works)

any help will be appriciated

网友答案:

I would suggest using the AjaxControlToolkit found at http://www.asp.net/ajaxlibrary/ajaxcontroltoolkitsamplesite/

Then if you want to add more than one you just reference the targetControlID. Here is an example of what I do with mine.

<asp:TextBox ID="tbAddDealDate" runat="server" Width="80px" Wrap="False" CausesValidation="false"></asp:TextBox>
                    <ajaxToolkit:MaskedEditExtender ID="tbAddDealDate_MaskedEditExtender" runat="server"
                        Enabled="True" TargetControlID="tbAddDealdate" Mask="99/99/9999" MaskType="Date" AutoComplete="True" ClearMaskOnLostFocus="true">
                    </ajaxToolkit:MaskedEditExtender>
                    <ajaxToolkit:CalendarExtender
                        ID="CalendarExtenderAddDealDate"
                        TargetControlID="tbAddDealDate"
                        runat="server" />

That website has some really nice examples with source code and it will be of great help to you I'm sure.

EDIT: Sorry, I read that wrong. What I would do is use two textboxes and hide one or the other. For example, if the user selects date, then show the textbox that uses the calendar extender. If they User selects name, then autocomplete feature textbox. This is how I would do it with mine. Here is the code I would use. I would set both textboxes invisible in the asp code. Then on the Selected index change insert the code below...

protected void ddlDropDownList_SelectedIndexChanged(object sender, Eventargs e)
{
    if(ddlDropDownList.Text == "Date")
     {
        tbCalendar.Visible = true;
        tbName.Visible = false;
     }
else if (ddlDropDownList.Text == "Name")
     {
        tbCalendar.Visible = false;
        tbName.Visible = true;
      }
}

Also in your asp, you will want to have AutoPostBack="true" and put your OnSelectedIndexChanged method in there so, OnSelectedIndexChanged="ddlDropDownList_SelectedIndexChanged" inside of your drop down list. I hope this helps! This will be the easiest solution in my opinion!

分享给朋友:
您可能感兴趣的文章:
随机阅读: