English 中文(简体)
• 如何使ava印成为纸面。
原标题:How to enable javascript in asp.net webforms

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 愿意这样做:

//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>

最佳回答

其实,不能确定伙伴关系是什么。 NET版本。 我认为,最后版本允许这样做(使服务器控制不为浏览器所理解的属性仍然存在)。 而是使用“onfocus”(下级)。

然而,如果你不为你工作,那么你就必须从后面的法典中这样做。

protected void Page_Load(object sender, EventArgs e)
{
    QuestionTextBox1。 Attributes["onfocus"]="someJavaScriptMethod";
}

或者,如果你在一页 j,你可以做些事情。

<script type="text/javascript">
$(function() {
    $( #<%= QuestionTextBox1。ClientID %> )。focus(someJavaScriptMethod);
});
</script>

如果你在<条形码>内读成正文(>),你可以使用<条码>这一词语(<>该),在集中控制时注明,并且你可以很容易地从该词中产生一个小标题,如<条码>>

Please leave me a comment if none of the above solves your problem。

问题回答

<asp:TextBox ID="TextBox1" runat="server" onfocus="TextBox1_focus(this, event)" onblur="TextBox1_blur(this, event)" Text="Search..."></asp:TextBox>

<script type="text/javascript">
    var searchText =  Search... ;

    function TextBox1_focus(sender, e) {
        if (sender.value == searchText)
            sender.value =   ;
    }

    function TextBox1_blur(sender, e) {
        if (sender.value ==   )
            sender.value = searchText;
    }
</script>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签