-1

午後全部、

Webページに2つのボタンがあり、Webページのロックとロック解除に使用されます。これにより、ユーザーはページをロックして編集でき、他のユーザーはレコードにアクセスできず、このレコードのロックを解除して他のユーザーが編集できるようになります。

私が抱えている問題は、ボタンが機能せず、理由がわからないことです。画像ボタンを使用していますが、イベントがトリガーされていないようです。問題が表示されず、気が狂います。誰かが私のコードを見てください...

   <asp:ImageButton ID="btnLock" runat="Server" 
       AlternateText="Click to lock record" ImageUrl="~/images/lock.png" />


   <asp:ImageButton ID="btnUnlock" runat="Server" 
       AlternateText="Click to unlock record" ImageUrl="~/images/unlock.png" />

   <asp:Label ID="lblUserName" runat="server" Font-Bold="True" Font-Size="Medium" 
            ForeColor="#CC3300"></asp:Label>
        <asp:HiddenField ID="hdnIsLockedBy" runat="server" />


 'VB Code for lock button...
  Protected Sub btnLock_Click(sender As Object, e As System.EventArgs) Handles btnLock.Click

    Dim lock As New WeeklyClass

    'Check that the Loggedby field is set to null so the user can then lock the record
    If String.IsNullOrEmpty(lock.LockedBy) Then
        'lock and add the username
        lock.LockedBy = User.Identity.Name
        'global variable islockedby
        hdnIsLockedBy.Value = User.Identity.Name
        'AgendaID required as part of the stored procedure 
        lock.AgendaID = Integer.Parse(lblAgendaNumber.Text)


    End If
    'Save to the database using the Class DAL and the Stored Procedure
    WeeklyClassDAL.LockWeeklyAgenda(lock)

    'Display buttons as expected result
    btnLock.Visible = False
    btnUnlock.Visible = True

    ' Refreshes fields on the page
    Response.Redirect("~/WeeklyAgenda.aspx?Edit=" & lblAgendaNumber.Text)

End Sub

  'VB Code for unlock button...
   Protected Sub btnUnlock_Click(sender As Object, e As System.EventArgs) Handles btnUnlock.Click

    Dim unlock As New WeeklyClass

    ' Check to see if the system has a username
    If hdnIsLockedBy.Value = User.Identity.Name Then
        'set the lockedby field to null
        unlock.LockedBy = hdnIsLockedBy.Value
        'pass the relevent agendaid
        unlock.AgendaID = Integer.Parse(lblAgendaNumber.Text)
    End If


    ' save to the database using the Class DAL
    WeeklyClassDAL.unLockWeeklyAgenda(unlock)

    'Display buttons as expected result
    btnLock.Visible = True
    btnUnlock.Visible = False

    ' Refreshes fields on the page
    Response.Redirect("~/WeeklyAgenda.aspx?Edit=" & lblAgendaNumber.Text)

End Sub

どんな助けでも大いに感謝します。私はこれを何年も前から見ていて、問題を見つけることができないようです。

よろしくベティ

4

3 に答える 3

0

ボタンでClickイベントを指定する必要があります。

OnClick="Button1_Click"

したがって、ボタンは次のようになります。

<asp:ImageButton 
            ID="btnLock" 
            runat="Server" 
            AlternateText="Click to lock record" 
            ImageUrl="~/images/lock.png" 
            OnClick="btnLock_Click" />

<asp:ImageButton 
           ID="btnUnlock" 
           runat="Server" 
           AlternateText="Click to unlock record" 
           ImageUrl="~/images/unlock.png" 
           OnClick="btnUnloc_Click />
于 2012-09-19T10:55:30.953 に答える
0

ボタンにautopostback="true"を追加する必要があります。

<asp:ImageButton ID="btnLock" runat="Server" autopostback="true"
       AlternateText="Click to lock record" ImageUrl="~/images/lock.png" />

そうしないと、コードビハインドはトリガーされません。

于 2012-09-19T10:55:50.330 に答える
0

クリックイベントを購読していません。コントロールは、ユーザーが関数をクリックしたときにそれらの関数を呼び出す必要があることを認識していません。

次のようにこれらのイベントを購読します。

<asp:ImageButton ID="btnLock" runat="Server" 
       AlternateText="Click to lock record" ImageUrl="~/images/lock.png"  
       OnClick="btnLock_Click" />


   <asp:ImageButton ID="btnUnlock" runat="Server" 
       AlternateText="Click to unlock record" ImageUrl="~/images/unlock.png"            
       OnClick="btnUnloc_Click />
于 2012-09-19T10:59:22.857 に答える