Detailsview Edit - Textbox

Last post 05-11-2007 9:00 PM by lionelthomas. 5 replies.

Sort Posts:

  • Detailsview Edit - Textbox

    05-11-2007, 12:30 PM

    Hi,

    I have a detailsview control with a textbox control containing a date.

    In edit and insert mode the date field is completed by picking a date from a popup calendar using javascript. All this works fine.

    Except the user can modify the textbox causing invalid data.

    How can I prevent the user from altering the data in the textbox.

    If the textbox is "readonly" it is not bound to the datasource.

    If "disabled=true" in html then javascript cannot change the value and data is not bound.

    Can anyone help?

    Regards,

    Lionel

  • Re: Detailsview Edit - Textbox

    05-11-2007, 2:37 PM
    • Loading...
    • kipo
    • Joined on 07-20-2006, 7:10 AM
    • Croatia
    • Posts 1,603

    Add CompareValidator to your TextBox:

    <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Invalid Date!" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator>

  • Re: Detailsview Edit - Textbox

    05-11-2007, 3:14 PM

    Hi,

    Thanks for the reply. I used the CompareValidator and now the date is invalid all the time.

    The format of my date is DD-MON-YYYY.

    I was hoping not to have to edit the date field at all.

    Regards,

    Lionel

  • Re: Detailsview Edit - Textbox

    05-11-2007, 3:41 PM
    • Loading...
    • kipo
    • Joined on 07-20-2006, 7:10 AM
    • Croatia
    • Posts 1,603

    Instead of TextBox, use Label which you fill with a date from your popup calendar and than in DetailsView1_ItemUpdating event use this code:

    protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            Label lbl = (Label)DetailsView1.FindControl("Label1");
            e.NewValues["ProductName"] = lbl.Text;
        }

  • Re: Detailsview Edit - Textbox

    05-11-2007, 4:06 PM

    Hi,

    Label is no good because it does not generate an html textbox.

    The javascript has no place to put the selected date

    self.opener.document.Form1.DetailsViewEvent$EventDate is null or not an object

    sorry,

    Regards,

    Lionel

  • Re: Detailsview Edit - Textbox

    05-11-2007, 9:00 PM
    Answer

    http://forums.asp.net/thread/1662016.aspx

    This thread describes a similar problem.

    The TextBox can easily be deactivated by including onkeydown="return false;"

    This prevents the user from entering anything into the textbox

    Regards,

    Lionel

Page 1 of 1 (6 items)
Microsoft Communities
Page view counter