Solved

Change Textbox Value on Selected Index Changed DDL not working

Posted on 2012-03-21
2
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 500 total points
ID: 37748318
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
ID: 37749154
Could I change the property to enabled and read only false instead of hidding it?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

749 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