English 中文(简体)
主页
原标题:Masterpages jquery

Hi i am using master pages webmethod for calling auto complete my code js is

   $(document).ready(function(e) {

    $( #ctl00_TextBox1 ).keyup(function(e) {
        //$( #ctl00_ContentPlaceHolder1_txtTest ).keyup(function(e) {
        alert("hi");
        var msgbox = $("#status");
        var tx_val = document.getElementById("ctl00_TextBox1").value;
        alert(tx_val);
        if (e.keyCode != 40 && e.keyCode != 39 && e.keyCode != 38 && e.keyCode != 37) {
            // debugger;
            // alert("hi");
            //debugger;

            $.ajax({

                // alert("ajax");
                type: "POST",
                //Page Name (in which the method should be called) and method name
                url: "Default.aspx/CheckDateTime",
                // If you want to pass parameter or data to server side function you can try line

                data: "{ args : " + tx_val + " }",
                //else If you don t want to pass any value to server side function leave the data to blank line below
                // data: "{}",

                contentType: "application/json; charset=utf-8",

                dataType: "json",

                success: function(msg) {
                    //Got the response from server and render to the client
                    msgbox.html(msg.d);
                }
            });
        };
    });
});

My problem is that this code runs in normal pages like aspx pages when I am using master page pages that the code is not working properly means code is running upto alert(tx)val); after ajax extension is not working

问题回答

你的身份证将根据哪一页(或者说是怎样封顶)加以改动,首先,我是这样取代:

var tx_val = document.getElementById("ctl00_TextBox1").value;

为此:

var tx_val = $(this).val();

The your selector, if it s in the page, do this:

$( #<%=TextBox1.ClientID%> ).keyup(function(e) {

如果在网页外面,就给它这样的一个类别:

<asp:TextBox Id="TextBox1" CssClass="dateTime" runat="server" />

并且将这一类别用于你的甄选者:

$( .dateTime ).keyup(function(e) {

......这还使你能够把你的文字完全放在外部,而不是依靠该页所产生的任何东西。


另一个潜在问题是<代码> Default.aspx/CheckDatetime" not being relative to the current path, can ensure where You are that this is appropriate, You may得着一条绝对的道路,如/Default.aspx/CheckDatetime. 如果这在每一页上,或者在你总是想去的某一页上,我可以听从你所张贴的法典。

其原因是,文本箱的客户比照时间更低。 在使用主页时,内容持有人还贴在客户旁边。 因此,你通过设定一个中断点和阅读客户信息数据库财产,更好地利用Nick Craver所建议的做法,或将新的客户进行 gr。

你们也可以按班级而不是id找到这一要素。

<asp:TextBox runat="server" CssClass="input" />

之后,您的格言如下:

var tx_val = $(".input").value;

你们需要改变你们的挑选者,像以下的法典一样,应当做以下工作:

var tx_val = $( input[id$=TextBox1] ).val();





相关问题
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!

热门标签