0

asp.netアプリケーションでad-Galleryコードを使用しています。データベースから写真をダウンロードしたかったので、少し一般的なものに変更しました。これは、すべての実装がコードビハインドにあることを意味します(これが私のC#コードの一部です):

ul.Attributes.Add("class", "ad-thumb-list");
            tabs.Controls.Add(ul);
            int i = 1;
                foreach (Products item in _PicturesPage)
                {
                    ul.Controls.Add(li);
                    anchor.Attributes.Add("href", item.ImagePath);
                    image.Attributes.Add("src", "../Images/pictures/thumbs/"+i+".jpg");
                    image.Attributes.Add("title","A title for 12.jpg");
                    image.Attributes.Add("alt", "This is a nice, and incredibly descriptive, description of the image");
                    image.Attributes.Add("class","image3");
                    li.Controls.Add(anchor);
                    anchor.Controls.Add(image);
                    i++;
                }

ハイパーリンク()の1つでクリックをインターセプトできるかどうか知りたいですか?ありがとうございました :)

4

1 に答える 1

1

JavaScriptイベントハンドラーを追加するだけです。

anchor.Attributes.Add("onclick", "YourJavaScriptFunction();");

falseリンクへのナビゲーションを防ぎたい場合は、必ずハンドラーから戻ってくださいhref

anchorのインスタンスをHtmlAnchor使用できる場合:

anchor.ServerClick += (sender, args) =>
    {
        // do stuff
    };
于 2012-11-18T23:49:57.363 に答える