Solved

Change Textbox Value on Selected Index Changed DDL not working

Posted on 2012-03-21
2
226 Views
Last Modified: 2012-06-27
HI EE

I need to make a texbox visible only when a selection is not null, (first selection), and then enable a texbox that gets populated with the current date, (user can change the date) I am using an update panel and setting up the autopostback property to true on the dropdown list, the problem is that the texbox is taking the selection on date when I insert to table....

can you please suggest what to do?

Thanks

<td style="width: 286px">
                <label for="recordtype">
                                 *Prepper:</label><asp:DropDownList 
                    ID="txtPreppin" runat="server" CssClass="padding-input" 
                    AutoPostBack="True" onselectedindexchanged="txtPreppin_SelectedIndexChanged">
                    <asp:ListItem Text="-Select-" Value=''>-Select-</asp:ListItem>
                    <asp:ListItem>Acevedo, Noe</asp:ListItem>
                </asp:DropDownList>
                <br />
                <label for="recordtype">
                                 *Date:</label>
<asp:TextBox ID="txtprepDate" runat="server" 
                    Enabled="False" ReadOnly="True"></asp:TextBox>
                <asp:CalendarExtender ID="txtprepDate_CalendarExtender" runat="server" 
                    Enabled="True" TargetControlID="txtprepDate" Format="MM/dd/yyyy">
                </asp:CalendarExtender>
               
                
               
        </td>

   protected void txtPreppin_SelectedIndexChanged(object sender, EventArgs e)
     {

         if (Page.IsPostBack)
         {

             txtprepDate.Text = DateTime.Today.ToString("MM/dd/yyy");
             txtScanDate.Text = DateTime.Today.ToString("MM/dd/yyy");


             if (txtPreppin.SelectedItem.Text != null)
             {
                 txtprepDate.Enabled = true;
                 txtprepDate.ReadOnly = false;
                                  
             }

             else
             {
                 txtprepDate.Enabled = false;
                 txtprepDate.ReadOnly = true;
             }
         }

Open in new window

0
Comment
Question by:TonyReba
2 Comments
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 500 total points
Comment Utility
This task can be done at the client side (on browser itself),so no need to do a round-trip to the server for this small task.
Simple, put the jquery link on your page and use the following code to achieve the same

$(function() {
      $("#txtbox").css("display","none");  // Hide the textbox on first page Load.

    $("#ddsListName").change(function() {
         if($(this).value != "0") // For the first element
         {
                 $("#txtbox").css("display","block");
         }
         else
         {
               $("#txtbox").css("display","none");
         }
     }
       
    );
});

Now in code behind,simple in the Page_Load event assign the textbox with current date.

That's done.
0
 
LVL 9

Author Comment

by:TonyReba
Comment Utility
Could I change the property to enabled and read only false instead of hidding it?
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now