i am trying to use javascript events in asp.net webforms. but events for input controls like textfield, such as onClick, onFocus,onBlur, dont appear. do i need to change my directive:
<%@ Page Title="" Language="C#" MasterPageFile="~/YourGuruMaster.master" AutoEventWireup="true" CodeFile="AskQuestion.aspx.cs" Inherits="AskQuestion" %>
i want to be able to do this:
//code page protected void Page_Load(object sender, EventArgs e) { QuestionTextBox1.Attributes["onfocus"] = "ClearSearchText()"; //Markup page function ClearSearchText() { var searchUserName = document.getElementById('<%=QuestionTextBox1.ClientID%>'); if (searchUserName.value = searchUserName.defaultValue) { searchUserName.value = ""; } return false; } <p dir="rtl" style=""> <asp:TextBox ID="QuestionTextBox1" runat="server" Width="702px" Text="פרטים עד 5000 תווים"></asp:TextBox>
AutoEventWireup
.onSomeEvent="method"
code, but forObject_Event
methods to work automatically, and they usually apply to things like page and user controls not text boxes and stuff, likePage_Load
.