Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ASP NET HTML Message Box talking to Code Behind Page
Message
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
ASP NET HTML Message Box talking to Code Behind Page
Divers
Thread ID:
00926132
Message ID:
00926132
Vues:
76
The following code may be of value to someone and if nothing else a starting point for the developer interested in such a concept. Comments are welcomed, as there are many ways to do anything with code.

Requirement:

Allow user to Delete record while provide a message box to Cancel or Delete record.

Approaches:

1. HTML Button (Note: Upon selecting Cancel, you will not cause a trip to the server)

2. Server side Button (Note: Upon selecting Cancel, you will cause a trip to the server)

Use one or the other approach as desired.

Details:

Use a Server Side Text Box, which will be used to send information from the HTML VB Script (or other scripting languages). The Code Behind Load will call the Delete Subroutine.

Set the Server Side Text Box as follows:
1. AutoPostBack = False
2. Text =
3. ReadOnly = False
4. Visible = True
5. Top = -100. This will hide the control and is essential if you use the HTML approach. If a Server Side Text Box approach is used you can set Visible=False, and position the control on the form.

Example:
Using VB Script on the HTML Page:
‘ HTML button
sub btnHTMLDelete_OnClick() 
‘ Disable buttons as required
form1.btnEdit.Disabled = "true" 
form1.btnAdd.Disabled = "true" 
form1.btnDelete.Disabled = "true" 

MessageDelete = MsgBox ("Do you really want to Delete this record?", 65, "MsgBox Example" )

if MessageDelete = 1 then 
     form1.txtMode.Value = "Delete" 
     form1.submit 
end if 

if MessageDelete = 2 then
     form1.txtMode.Value = "" 
     form1.btnEdit.Disabled = "false" 
     form1.btnAdd.Disabled = "false" 
     form1.btnDelete.Disabled = "false" 
end if 

end subServer Side Button

Sub btnDelete_OnClick() 
form1.btnEdit.Disabled = "true" 
form1.btnAdd.Disabled = "true" 
form1.btnDelete.Disabled = "true" 

MessageDelete = MsgBox ("Do you really want to Delete this record?", 65, "MsgBox Example" )

if MessageDelete = 1 then 
     form1.txtMode.Value = "Delete" 
     form1.submit 
end if 

if MessageDelete = 2 then 
     form1.txtMode.Value = "" 
     form1.btnEdit.Disabled = "false" 
     form1.btnAdd.Disabled = "false" 
     form1.btnDelete.Disabled = "false" 
end if 

end sub

Code Behind

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If txtMode.Text = "Delete" Then
                
     Dim userID = txtUserID.Text
     ‘ Call DeleteUser routine…
     DeleteUser(userID)
     txtMode.Text = ""           

End If

End Sub
Répondre
Fil
Voir

Click here to load this message in the networking platform