2009-11-20 6 views

Répondre

1

Si vous parlez d'un côté client événement onclick vous pouvez utiliser la propriété OnClick dans la concepteur, ou vous pouvez ajouter manuellement l'événement "onclick" dans le code.

Pour la méthode onclick essayez ce qui suit:

//asp will allow the onclick event to pass through to the webpage 
<asp:textbox onclick="myJavaScriptFunction()" runat="server" id="myTextBox" ... > 

Pour ajouter l'attribut essayer manuellement ceci:

myTextBox.Attributes.Add("onclick", "myJavaScriptFunction()"); 
+0

Ne pensez pas que System.Web.UI.WebControls.TextBox prend en charge OnClientClick –

+0

merci cxfx, j'ai mis à jour ma réponse, vous avez raison. –

0
<asp:TextBox runat="server" ID="MyTextbox" onclick="alert('click')" /> 
0

Sélectionnez la zone de texte Aller à "Propriétés" dans le bas coin droit Cliquez sur l'éclair (événements)

et là vous verrez une liste d'événements, textchanged, onload etc. Dans là vous mettez dans votre nom de méthode et commencez la programmation!

0

Vous voulez dire?

txtBox1.Attributes.Add("onClick","javascript:doSomething()");

0

Vous devez vous inscrire js événement

textBox1.Attributes.Add("onclick","javascript:alert('ALERT ALERT!!!')") 
2

Si vous cherchez événement click côté serveur. Essaye ça.

public class TextBox : System.Web.UI.WebControls.TextBox, System.Web.UI.IPostBackEventHandler 
{ 

    private static readonly object _clickEvent = new object(); 

    [System.ComponentModel.Category("Action")] 
    public event EventHandler Click 
    { 
     add { base.Events.AddHandler(_clickEvent, value); } 
     remove { base.Events.RemoveHandler(_clickEvent, value); } 
    } 

    protected virtual void OnClick(EventArgs e) 
    { 
     EventHandler handler = (EventHandler)base.Events[_clickEvent]; 
     if (handler != null) handler(this, e); 
    } 

    protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer) 
    { 
     base.AddAttributesToRender(writer); 

     writer.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Onclick, base.Page.ClientScript.GetPostBackEventReference(this, null)); 
    } 

    #region IPostBackEventHandler Members 

    void System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(string eventArgument) 
    { 
     this.OnClick(EventArgs.Empty); 
    } 

    #endregion 

} 

<pages> 
    <tagMapping> 
    <add tagType="System.Web.UI.WebControls.TextBox" 
     mappedTagType="{namespace}.TextBox"/> 
    </tagMapping> 
</pages> 
0

Vous pouvez utiliser JS pour Concern.
définir une méthode JS pour OnClick Event, Say doSomething() entre Script Tag dans la ASP page Et Call la méthode de la TextBox

Questions connexes