Determinar cuándo se hace clic en ASP TextBox

I cant seem to find an event that is fired when a user clicks on an ASP TextBox. Is there an event that is fired? Is the only way to handle this through javascript? If possible, Id like to do it in the code behind.

preguntado el 30 de enero de 12 a las 19:01

3 Respuestas

No, there is no OnClick event raised on the server side when the text element is clicked. You can add an onclick handler on javascript an issue a postback to the page. For example:

<asp:TextBox onclick="myFunc();" ID="das" runat="server"></asp:TextBox>

Y luego algo como:

function myfunc()
{
    var theForm = document.forms['aspnetForm'];
    theForm.__EVENTTARGET.value = eventTarget; //could be any string 
    theForm.__EVENTARGUMENT.value = eventArgument;//could be any string
    theForm.submit();
}

En el lado del servidor:

string eventTarget=Request.Params["__EVENTTARGET"]; //etc

Respondido el 31 de enero de 12 a las 00:01

Aquí debe visitar el OnCheckedChanged event but it is only fired on post back unless you have autopostback establecido en verdadero.

Respondido el 30 de enero de 12 a las 23:01

TextBox doesn't have Click event at server-side.

But, textBox is a web control which supports attributes, so you could in fact use this to create a javascript click action. Either set this on aspx

<asp:TextBox ID="TextBox1" runat="server" OnClick="" /> 

or this in code

Me.TextBox1.Attributes("onclick") = ""

Respondido el 31 de enero de 12 a las 00:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.