c# - Guid format is not Recognised -
i error in dropdownlist
when it's converting string guid.
stack trace: @ system.guid.guidresult.setfailure(parsefailurekind failure, string failuremessageid, object failuremessageformatargument, string failureargumentname, exception innerexception) @ system.guid.tryparseguid(string g, guidstyles flags, guidresult& result) @ system.guid..ctor(string g) @ projects_addproject.wizcreateproject_activestepchanged(object sender, eventargs e) @ system.web.ui.webcontrols.wizard.onactivestepchanged(object source, eventargs e) @ system.web.ui.webcontrols.wizard.multiviewactiveviewchanged(object source, eventargs e) @ system.web.ui.webcontrols.multiview.onactiveviewchanged(eventargs e) @ system.web.ui.webcontrols.multiview.set_activeviewindex(int32 value) @ system.web.ui.webcontrols.wizard.set_activestepindex(int32 value) @ projects_addproject.proxy_navigate(object sender, historyeventargs e) @ system.web.ui.scriptmanager.raisenavigate(historyeventargs e) @ system.web.ui.scriptmanager.loadhistorystate(string serverstate) @ system.web.ui.scriptmanager.raisepostbackevent(string eventargument) @ system.web.ui.scriptmanager.system.web.ui.ipostbackeventhandler.raisepostbackevent(string eventargument)
the method wizcreateproject_activestepchanged. need know how fix conversion.
here method error:
protected void wizcreateproject_activestepchanged(object sender, eventargs e) { switch (wizcreateproject.activestepindex) { case 0: if (rbfrmtemp.checked) { int tenantid = tenantutils.gettenantid(page); ezproject templateproject = dbaccessprojects.getproject(tenantid, new guid(ddlprojtemplates.selectedvalue)); default: break; } }
i error in line:
ezproject templateproject = dbaccessprojects.getproject(tenantid, new guid(ddlprojtemplates.selectedvalue));
i checked ddlprojecttemplates have type of vaues
<option value="7590aab2-29b9-4262-9982-4403ca7b52f2">managed services agreement</option>
is correct guid format. how can fix issue?
my guess drop down list selection being trashed when post , picking first thing in drop down list, empty , guid conversion fails. protect guid conversion have applied values not null or not empty, this:
if(!string.isnullorempty(ddlprojtemplates.selectedvalue)) { // know there value attempt convert ezproject templateproject = dbaccessprojects.getproject(tenantid, new guid(ddlprojtemplates.selectedvalue)); }
for greater protection, use guid.tryparse()
method instead of guid
constructor, this:
guid newguid; if (guid.tryparse(ddlprojtemplates.selectedvalue, out newguid)) { ezproject templateproject = dbaccessprojects.getproject(tenantid, newguid); }
Comments
Post a Comment