Attribute not associate with control in FormView InsertMode

Last post 07-04-2008 7:02 AM by mrkashifali. 2 replies.

Sort Posts:

  • Attribute not associate with control in FormView InsertMode

    07-01-2008, 6:23 AM
    • Member
      point Member
    • mrkashifali
    • Member since 07-01-2008, 6:08 AM
    • Posts 2

    In InsertItem Template of a FormView, I want to execute a JavaScript on "onChange" event of a textbox. I have written following code for this

    protected void myFormView_ItemCommand(object sender, FormViewCommandEventArgs e)

    {

    if (e.CommandName == "New" || e.CommandName == "Edit")

    {

    TextBox txtStaffName = ((TextBox)myFormView.FindControl("txtStaffName"));
    txtStaffName.Attributes.Add("onChange", "dataChanged();");

    }

    }

    The dataChanged() javascript method is running in Edit mode of formview but is not working in Insert mode!!!

    The control name in both insert and edit template is the same i.e. txtStaffName

    Please help where should i place this code. Or how should i add this attribute with this control.

     Thank you

  • Re: Attribute not associate with control in FormView InsertMode

    07-02-2008, 11:45 PM
    Answer

    Hi mrkashifali ,

    I strongly suspect whether the javascript is registed to the control.

    You can write code in PreRender event instead. And what I want to remind is that the onchange event will fired when mouse leave the control.

     

        protected void FormView1_PreRender(object sender, EventArgs e)
        {
            if ((this.FormView1.CurrentMode == FormViewMode.Edit) || (this.FormView1.CurrentMode == FormViewMode.Insert))
            {
                //code here
            }
        }

     

     


    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
  • Party!!! [<:o)] Re: Attribute not associate with control in FormView InsertMode

    07-04-2008, 7:02 AM
    • Member
      point Member
    • mrkashifali
    • Member since 07-01-2008, 6:08 AM
    • Posts 2

    Thanks Samu Zhang, it worked.

Page 1 of 1 (3 items)