如何从asp.net中动态创建的文本框中调用javascript?

时间:2012-09-23 16:55:10

标签: javascript asp.net c#-4.0 dynamic textbox

 // Assign Context-Menu to Control
    $(function () {
        var txt1 = "#" + "<%= **myCal**.ClientID %>";

        // Attach Context-Menu to Control
        $(txt1).contextMenu(ctxtMenu, { theme: 'vista' });
    });

代码

            TextBox lbl = new TextBox ();
            lbl.BorderColor = System.Drawing.Color.Black;
            lbl.BorderStyle = BorderStyle.Double;
            lbl.BackColor = System.Drawing.Color.BlanchedAlmond;
            lbl.Text = eventname + "<br/>" + dt + "" + dt1;
            e.Cell.Controls.Add(lbl);

我想使用动态创建的asp.net TextBox代替myCal

我该怎么办?请帮忙

1 个答案:

答案 0 :(得分:1)

您可以为此控件定义一个CSS类:

lbl.CssClass = "menu";

然后使用类选择器:

$(function () {
    // Attach Context-Menu to Control
    $('.menu').contextMenu(ctxtMenu, { theme: 'vista' });
});