Portal Engine
Version 2.x > Portal Engine > Customizing Bizform View modes: 
User avatar
Member
Member
mateo - 4/28/2007 8:59:52 AM
   
Customizing Bizform
does anyone have samples of code using BizForm.OnBeforeSaveEventHandler?

I am trying to update a bizform with data from a wizard control and the bizform field is hidden from the form so I need to update the database with the data when it is saved.

cheers.

User avatar
Member
Member
forrester - 5/2/2007 11:10:10 PM
   
RE:Customizing Bizform
Hi Mateo,

I am in the process of doing something similar, and Kentico provided me with the following example. Maybe this will help you.

1) Add the following line to OnContentLoaded() method of the BizForm webpart -
BizFormNew.OnAfterSave += new BizForm.OnAfterSaveEventHandler(BizFormNew_OnAfterSave);

2) Create new method:
void BizFormNew_OnAfterSave()
{
// here you can place your code
}

I am, however, having problems with the OnAfterSave event not being called. I cannot get a breakpoint in CMSWebParts - Bizform.aspx. If you find a solution for your customization, could you please post it and I will do the same as well once I do.

Thanks,
forrester

User avatar
Member
Member
mateo - 5/17/2007 6:58:57 AM
   
RE:Customizing Bizform
hey forrester,

i was able to get the following to work, sorry i code in vb...


Private Sub BizForm_OnAfterSave() Handles Bizform1.OnAfterSave
Dim cn As New SqlClient.SqlConnection
cn.ConnectionString = ConfigurationManager.AppSettings("DBConnectionString")

'Select FormItem Count from CMS_Form
Dim strSQL As String
Dim contactid As Integer
strSQL = "SELECT contactid From Form_Contact Order By ContactId Desc"
Dim myCatCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, cn)
Dim myCatDataReader As SqlClient.SqlDataReader
Try
cn.Open()
myCatDataReader = myCatCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
If myCatDataReader.Read() Then
contactid = myCatDataReader("contactid")
End If
myCatDataReader.Close()
Catch myException As Exception
Response.Write(myException)
Response.End()
Finally
cn.Close()
End Try

If Not IsDBNull(contactid) Then
'Update FormItem Count to +1
Dim dbCommand As New SqlClient.SqlCommand
dbCommand = New SqlClient.SqlCommand
dbCommand.Connection = cn
dbCommand.CommandText = "UPDATE Form_Contact SET WhitePapers=@WhitePapers WHERE ContactId=@ContactId"
dbCommand.Parameters.Add(New SqlClient.SqlParameter("@ContactId", SqlDbType.Int))
dbCommand.Parameters("@ContactId").Value = contactid

dbCommand.Parameters.Add(New SqlClient.SqlParameter("@WhitePapers", SqlDbType.NVarChar))
dbCommand.Parameters("@WhitePapers").Value = Session("ArticleTitle")

Try
cn.Open()
dbCommand.ExecuteNonQuery()
Catch ex As SqlClient.SqlException
Response.Write(ex.Message & "Survey Details.")
Response.End()
Finally
cn.Close()
Bizform1.Visible = False
End Try
End If

End Sub