onblur in an UpdatePanel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?c21heQ==?=

    onblur in an UpdatePanel

    I'm having trouble with a datagrid in an UpdatePanel that includes a user
    control in the footer and edit rows. The user control references a js file
    that initializes an onblur for the textbox it contains. This is fine when
    the page loads however after clicking the add button, the update panel
    refreshes showing me the row I added and a new footer, but the code contained
    in the onblur function has been added to the page's javascript as if it were
    a validator. The problem is that at this point it can no longer reference
    the appropriate objects. In other words, near the bottom of my code snippets
    below, "doStuff(oThis. textbox);" is being placed into the anonymous
    javascript function at the bottom, which then throws an error because oThis
    is undefined. Can anyone tell me why this is happening and how to avoid it?
    Any I doing something wrong that is causing this?

    Parent Page HTML:
    <asp:UpdatePane l ID="up1" runat="server">
    <ContentTemplat e>
    <asp:DataGrid ID="Components " runat="server" ...>
    <Columns>
    <asp:TemplateCo lumn>
    <FooterTemplate >
    <asp:PlaceHolde r ID="ph" runat="server"> </asp:PlaceHolder >
    </FooterTemplate>
    </asp:TemplateCol umn>
    </Columns>
    </asp:DataGrid>
    </ContentTemplate >
    </asp:UpdatePanel >

    Parent Page CodeBehind:
    Dim excip As New myUC
    Protected Sub Page_Init
    initUC()
    End Sub

    Private Sub initUC()
    excip = CType(LoadContr ol("~/myUserControl.a scx"), myUC)
    End Sub

    Private Sub Page_Load
    BuildDataGrid()
    End Sub

    Protected Sub Components_Item DataBound
    Select Case e.Item.ItemType
    Case ListItemType.Fo oter
    Dim ph As PlaceHolder = CType(e.Item.Fi ndControl("ph") , PlaceHolder)
    excip.Property1 = ""
    excip.Property2 = ""
    ph.Controls.Add (excip)
    End Sub

    Protected Sub Components_Item Command
    'save info

    initCBO()
    BuildDataGrid()
    End Sub


    User Control HTML:
    <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
    <asp:Literal ID="Literal1" runat="server"> </asp:Literal>

    User Control CodeBehind:
    Private Sub Page_Load
    If (Not Page.ClientScri pt.IsClientScri ptIncludeRegist ered(Me.GetType ,
    "jsRef")) Then
    Page.ClientScri pt.RegisterClie ntScriptInclude (Me.GetType, "jsRef",
    ResolveClientUr l("~/myUserControl.j s"))

    Dim sb as New StringBuilder
    sb.Append("dyna mic javascript")
    ScriptManager.R egisterStartupS cript(Literal1, Me.GetType(), "dynamicJS" ,
    sb.ToString, False)
    End If
    End Sub


    myUserControl.j s:
    function myStuff(txtbox) {
    this.textbox = txtbox;

    this.init();
    }

    myStuff.prototy pe.init = function () {
    var oThis = this;

    this.textbox.on blur = function (event) {
    doStuff(oThis.t extbox);
    };
    };


    Produced validation code:
    function anonymous() {
    ValidatedContro lOnBlur(event);
    doStuff(oThis.t extbox);
    }
Working...