开发者

ParseControl in Dotnetnuke ASP.NET changing onclick to javascript instead of c# method provided, strange behavior

Having some strange behavior here. I have some XSLT which generates some html with a few ASP.NET Link Button Controls

 String mstring = sw.ToString();
 var myctrl = Page.ParseControl(mstring);

      foreach (Control Control in myctrl.Controls)
              {
                  if (Control is LinkButton)
                      {
                         LinkButton lb = (LinkButton)Control;
                         lb.OnClientClick = "LoadPromo";

                       }
                          Panel1.Controls.Add(myctrl);
               }  

  protected void LoadPromo(object sender, EventArgs e)
        {
            Console.Write(e.ToString());

        }

now it takes this control:

<asp:LinkButton ID="LinkButton2" runat="server" OnClick="LoadPromo" Text="Get your Free 2" />

and cha开发者_StackOverflownges it to this when I add an event:

<a onclick="LoadPromo;" id="dnn_ctr954_ViewPromotions_LinkButton2" href=" WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("dnn$ctr954$ViewPromotions$LinkButton2", "", true, "", "", false, true))">Get your Free 2 a>

Now as you can see, it changes the onclick to like javascript instead of the asp.net control.It changes "LoadPromo" to "LoadPromo;". What can i do to get around this?

Thanks In Advance

Things I have tried:

 lb.Click += LoadPromo;

I get this output:

<a id="dnn_ctr954_ViewPromotions_LinkButton2" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;dnn$ctr954$ViewPromotions$LinkButton2&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))">Get your Free 2</a>


OnClientClick is the name of the property of a server control that eventually renders to an "onclick" attribute. This is meant to invoke a javascript function on the client side. So in this case, it looks fine.

For the OnClick property, you need to have that match the name of a server-side function in your Page.aspx. I'm not sure why it would even be rendering the onclick attribute for this - perhaps you don't have a function named "LoadPromo" with the right signature?

You should have a C# method like this:

protected void LoadPromo(object sender, EventArgs e)
{

}

Then you can wire this up to your button by doing

myLinkButton.Click += LoadPromo;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜