ASP.NET w/ VB.NET - Winforms to Web - NullReferenceException Error on string split / string builder -


background: have winform app registers user in database based on information provided, auto-generates random password , username, , e-mails user link take application based on marketing company selected.

problem:

  • when user clicks "send invitation" data inputted iton fields except bundles listbox in debug, nullreferenceexception error thrown highlighting line: dim mcshort string = trim(splitmc(0))

how fix issue

here's screenshot of web app:

web app screenshot

here's code of send_button_click method off default.asx.vb:

private sub send_button_click(byval sender system.object, byval e system.eventargs) handles send_button.click      'todo add code validate selections reaquired met.     'ccemail , additional message not required     dim firstname string = txtfirstname.text     dim lastname string = txtlastname.text     dim ccemail string = txtccemail.text      dim sb new stringbuilder      sb.appendline("<?xml version=""1.0"" encoding=""utf-8""?>")     sb.appendline("<root>")     sb.appendline("<marketingcompany>")     sb.appendline("<marketingcompanyname>")      ''get marketing company short name     dim splitmc string() = split(marketingco.selecteditem, "|")     dim mcshort string = trim(splitmc(0))     sb.appendline(string.format("<mcname>{0}</mcname>", mcshort))       'sb.appendline(string.format("<mcname>{0}</mcname>", my.settings.marketingcompanyshortname))      sb.appendline(string.format("<ccemail>{0}</ccemail>", txtccemail.text))     sb.appendline(string.format("<emailmessage>{0}</emailmessage>", txtmessage.text))     sb.appendline(string.format("<marketername>{0}</marketername>", txtmarketername.text))     sb.appendline("<agent>")     sb.appendline(string.format("<firstname>{0}</firstname>", txtfirstname.text))     sb.appendline(string.format("<lastname>{0}</lastname>", txtlastname.text))     sb.appendline(string.format("<email>{0}</email>", txtemail.text))     sb.appendline("<crmguid>123456</crmguid>")      dim spltbundles() string      each item in bundles.items         if trim(item) <> ""             spltbundles = split(item, "|")             sb.appendline("<contractingopportunity>")             sb.appendline(string.format("<carrier>{0}</carrier>", trim(spltbundles(0))))             sb.appendline(string.format("<contractingopportunityname>{0}</contractingopportunityname>", trim(spltbundles(1))))             sb.appendline("</contractingopportunity>")         end if     next      sb.appendline("</agent>")     sb.appendline("</marketingcompanyname>")     sb.appendline(" </marketingcompany>")     sb.appendline(" </root>")     dim xmlstr = sb.tostring       dim int1 boolean = proxy.addcontractopportunity(xmlstr.tostring, "test", "test")      msgbox("acomp invitation sent! :)")   end sub 

for first question, can use onselectedindexchanged event lbcarriers.

regarding missing data question when submit, should use sort of validation on submitted page. asp.net includes a set of validation controls make job easy. @ simplest level, can set form controls required , allow form prompt user fill out required fields before code-behind events fire.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -