Thank you Master. I would like to get the Value from a text box. After I clicked the button, the error message displayed. How to solve it?
Error Message
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error:
Line 134: toSet.SetValue(orgdoctortel.Text).SetFontAndSize(font, 0)
Line 135: fields.TryGetValue("relationship", toSet)
Line 136: toSet.SetValue(relationship.Text).SetFontAndSize(font, 0)
Line 137: fields.TryGetValue("relativePhone", toSet)
Line 138: toSet.SetValue(relativePhone.Text).SetFontAndSize(font, 0)
|
Source File: D:\inetpub\wwwroot\eTransferPatient\input1.aspx.vb Line: 136 Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
input1.Button1_Click(Object sender, EventArgs e) in D:\inetpub\wwwroot\eTransferPatient\input1.aspx.vb:136
input1.btnDraft_Click(Object sender, EventArgs e) in D:\inetpub\wwwroot\eTransferPatient\input1.aspx.vb:1657
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11596287
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +273
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1889
|
thank you.
Here is the code:
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
'Get patient information from IT web service
Dim getInfo As New nsdeform.getPatientInformationSoapClient
Dim qstr_patCode As String = Request.QueryString("patCode")
Dim qstr_userID As String = Request.QueryString("userID")
Dim patinfo = getInfo.getPatientInfoByPatCode("nsd5EvgIKL!", qstr_patCode, qstr_userID)
'Dim patinfo = getInfo.getPatientInfoByPatCode("nsduat1$", qstr_patCode, qstr_userID)
'Fill form template with data
Dim newform As String = Guid.NewGuid().ToString
iText.IO.Util.ResourceUtil.AddToResourceSearch("itext.font_asian.dll")
Dim fontA As PdfFont = PdfFontFactory.CreateFont("C:/Windows/Fonts/arialuni.ttf", PdfEncodings.IDENTITY_H, False)
Dim font As PdfFont = PdfFontFactory.CreateFont("C:/Windows/Fonts/simhei.ttf", PdfEncodings.IDENTITY_H, False)
Dim pdf_template As String = "PDF/MR NSD 0555 2P.pdf"
If qstr_userID = "khs901" Then
'for testing
'2 page form
pdf_template = "PDF/MR NSD 0555 2page.pdf"
fontA = PdfFontFactory.CreateFont("C:/Windows/Fonts/arialuni.ttf", PdfEncodings.IDENTITY_H, False)
font = PdfFontFactory.CreateFont("C:/Windows/Fonts/simhei.ttf", PdfEncodings.IDENTITY_H, False)
End If
Dim reader As New PdfReader(Server.MapPath(pdf_template))
'New filled form file name
Dim writer As New PdfWriter(Server.MapPath("PDF/" & newform & ".pdf"))
Dim pdf As New PdfDocument(reader, writer)
Dim doc As New Document(pdf)
Dim form As PdfAcroForm = PdfAcroForm.GetAcroForm(pdf, True)
'Try
'form = PdfAcroForm.GetAcroForm(pdf, True)
' Catch ex As Exception When TypeOf ex Is iText.IO.IOException
'End Try
Dim fields As IDictionary(Of String, PdfFormField) = form.GetFormFields()
Dim toSet As PdfFormField
'doc.SetFontAndSize(font, 14)
pdf.AddFont(font)
fields.TryGetValue("changedate", toSet)
toSet.SetValue(changedate.Text).SetFontAndSize(font, 0)
fields.TryGetValue("fromunit", toSet)
toSet.SetValue(fromunit.Text).SetFontAndSize(font, 0)
fields.TryGetValue("tounit", toSet)
toSet.SetValue(tounit.Text).SetFontAndSize(font, 0)
fields.TryGetValue("orgdoctor", toSet)
toSet.SetValue(orgdoctor.Text).SetFontAndSize(font, 0)
fields.TryGetValue("orgdoctortel", toSet)
toSet.SetValue(orgdoctortel.Text).SetFontAndSize(font, 0)
fields.TryGetValue("relationship", toSet)
toSet.SetValue(relationship.Text).SetFontAndSize(font, 0)
fields.TryGetValue("relativePhone", toSet)
toSet.SetValue(relativePhone.Text).SetFontAndSize(font, 0)
pdf.Close()
doc.Close()
'Save to submission history
SqlDataSource2.InsertParameters.Add("formid1", newform.ToString)
SqlDataSource2.InsertParameters.Add("corpid1", qstr_userID)
SqlDataSource2.InsertParameters.Add("unit1", patinfo.ward.Trim)
SqlDataSource2.InsertParameters.Add("patientHN1", patinfo.hn.Trim)
SqlDataSource2.InsertParameters.Add("patientName1", patinfo.patient_name.Trim)
SqlDataSource2.InsertParameters.Add("date1", Now().ToString("yyyy-MM-dd HH:mm:ss"))
'If (qstr_userID = "wyc504" Or qstr_userID = "lkw414a" Or qstr_userID = "leunlm1") And lblDraft.Text = "Yes" Then
If lblDraft.Text = "Yes" Then
'For draft, mark draft in formstatus field
SqlDataSource2.InsertCommand = "INSERT INTO submission (formid,corpid,unit,patientHN,patientName,date,formstatus) values (@formid1,@corpid1,@unit1,@patientHN1,@patientName1,@date1,'draft')"
Else
SqlDataSource2.InsertCommand = "INSERT INTO submission (formid,corpid,unit,patientHN,patientName,date,formstatus) values (@formid1,@corpid1,@unit1,@patientHN1,@patientName1,@date1,'')"
End If
SqlDataSource2.Insert()
'Delete over 7 days records
'SqlDataSource3.DeleteParameters.Add("corpid2", qstr_userID)
'SqlDataSource3.DeleteCommand = "DELETE FROM submission WHERE (corpid=@corpid2) AND (date<DATEADD(week,-1,GETDATE()))"
'SqlDataSource3.Delete()
If lblDraft.Text = "Yes" Then
Response.Redirect("SaveDraft.aspx")
End If
Response.Redirect("print.aspx?formid=" & newform)
End Sub