1

ASP.NET と VB を使用して動的な Web ソリューションを作成しようとしています。

私のウェブページは次のようになります。

<div id="menu" style="position:relative;text-align:center">
        <asp:PlaceHolder runat="server" id="PHimg1" />
        <asp:PlaceHolder runat="server" id="PHimg2" />
        <asp:PlaceHolder runat="server" id="PHimg3" />
        <br />
        <asp:PlaceHolder runat="server" id="PHimg4" />
        <asp:PlaceHolder runat="server" id="PHimg5" />
        <asp:PlaceHolder runat="server" id="PHimg6" />
        <br />
        <asp:PlaceHolder runat="server" id="PHimg7" />
        <asp:PlaceHolder runat="server" id="PHimg8" />
        <asp:PlaceHolder runat="server" id="PHimg9" />
</div>

このようなVB部分:

Public Class index
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Load_Main()
End Sub

Protected Sub Load_Main()
    Dim img1 As New ImageButton()
    Dim img2 As New ImageButton()
    Dim img3 As New ImageButton()
    Dim img4 As New ImageButton()
    Dim img5 As New ImageButton()
    Dim img6 As New ImageButton()

    img1.ImageUrl = "./resources/EssenTrinken.png"
    img1.OnClientClick = "Load_Eating()"

    img2.ImageUrl = "./resources/Einkaufen2-black.png"
    img3.ImageUrl = "./resources/Special-black.png"
    img4.ImageUrl = "./resources/KosmetikWellness.png"
    img5.ImageUrl = "./resources/KulturGeschichte.png"
    img6.ImageUrl = "./resources/Unterhaltung2-black.png"

    PHimg1.Controls.Add(img1)
    PHimg2.Controls.Add(img2)

    PHimg4.Controls.Add(img3)
    PHimg5.Controls.Add(img4)

    PHimg7.Controls.Add(img5)
    PHimg8.Controls.Add(img6)
End Sub

Protected Sub Load_Eating()
    Dim img1 As New ImageButton()
    Dim img2 As New ImageButton()
    Dim img3 As New ImageButton()
    Dim img4 As New ImageButton()
    Dim img5 As New ImageButton()
    Dim img6 As New ImageButton()

    img1.ImageUrl = "./resources/zurueck.png"
    img2.ImageUrl = "./resources/Bars2.png"
    img3.ImageUrl = "./resources/Cafe.png"
    img4.ImageUrl = "./resources/FastFood2.png"
    img5.ImageUrl = "./resources/Restaurant.png"
    img6.ImageUrl = "./resources/Baeckerei.png"

    PHimg1.Controls.Add(img1)
    PHimg2.Controls.Add(img2)

    PHimg3.Controls.Add(img3)
    PHimg4.Controls.Add(img4)

    PHimg5.Controls.Add(img5)
    PHimg6.Controls.Add(img6)
End Sub

End Class

imagebutton の 1 つをクリックすると、新しいホール ページをロードせずに、フロント ページのホールの外観が動的に変化するようにします。そこで、そのためにいくつかの PlacHolder を定義しました。

webapp を実行しても、ボタンを押しても機能が動作しない場合。

ソースを確認したところ、次のタグが見つかりました。

<input type="image" name="ctl03" src="./resources/EssenTrinken.png" onclick="Load_Eating();" />

このソリューションの何が問題になっていますか?

4

2 に答える 2

1

Page_load にIsPostBackのチェックを追加します

if Not IsPostBack Then
   Load_main()
End If

これにより、page_load メソッドがすべてのボタンを再作成し、Image_click イベントの値をリセットできなくなります。

于 2013-03-31T22:45:55.743 に答える
1

If you are trying to do this from the code behind, then you need to add the Click event handler:

Protected Sub Load_Main()
    Dim img1 As New ImageButton()    
    AddHandler img1.Click, AddressOf Img1Click
    'rest of your code

and then have some function that does what you want:

Private Sub Img1Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
    'some code
End Sub

Note, this will cause a postback. It is confusing on how you expect to dynamically change the front page without reloading the page and without using JavaScript...

于 2013-03-31T23:03:12.160 に答える