Is there any way (syntax) to organize such a call to the SetInputText method of the onblur event?

<asp:TextBox runat="server" ID="tbFirstName" onfocus="$.ClearInput(this);" onblur='$.SetInputText(this, "<%=regFirstName%>");' /> 

    1 answer 1

    It is impossible to do this through markup, only in the code-behind. Therefore, remove onblur in the markup and create a handler for Init 'and control:

     <asp:TextBox runat="server" ID="tbFirstName" onfocus="$.ClearInput(this);" OnInit="tbFirstName_Init" /> 

    And in the code:

     protected void tbFirstName_Init(object sender, EventArgs e) { ((TextBox)sender).Attributes["onblur"] = string.Format("$.SetInputText(this, '{0}')", regFirstName); } 

    Or, if you can C # 6, then:

     protected void tbFirstName_Init(object sender, EventArgs e) { ((TextBox)sender).Attributes["onblur"] = $"$.SetInputText(this, '{regFirstName}')"; } 
    • Class, I didn’t think about behind, thanks! - Gandolf