如何使用htmlgenericcontrol在c#中添加javascript函数

时间:2012-08-23 08:41:51

标签: c# asp.net

我正在使用asp.net c#。我想通过使用htmlgeneric控件在c#中添加javascript函数。我使用了代码,

HtmlGenericControl scriptTagLinks = new HtmlGenericControl("script");
scriptTagLinks.Attributes["type"] = "text/javascript"; 
string scrip = "$(function () {$([src='" + url + "']" + ").pinit();});";
    // txtDesc.Text = rdr.GetString(4);
    // TxtLink.Text = rdr.GetString(6);
scriptTagLinks.Attributes["src"] = scrip;
this.Controls.Add(scriptTagLinks);

但我应该这样,

 <script type="text/javascript">
   $(function () {


        $("[src='/pinterest/portals/0/Images/about-person3.jpg']").pinit(); 
        $("[src='/pinterest/portals/0/Images/about-us-group.jpg']").pinit();

    });
    </script>

但我得到的是

 <script src="$(function () {$([src='/pinterest/portals/0/Images/about-us-group.jpg']).pinit();});" type="text/javascript">

如何在代码之间添加$([src='/pinterest/portals/0/Images/about-us-group.jpg']).pinit();});

0 个答案:

没有答案