so I have a visual webpart for registering/unregistering for an event on top of a custom lists' ("events"-list) display form (added via &ToolPaneView=2).
Now my use-case is this: potential Attendee opens the display form and wants to register. But he has to [get some coffee first, etc...] first - so he lets the display form openend.
While [attendee gets coffee etc...] an Editor deletes the corresponding Entry of the events-list.
Now later on, the potential attendee comes back and tries to register for the - now deleted - event. And now there's my problem: Instead of showing a) the error message as defined in my catch-block, or b) redirecting as you could see in the code I'll add, I get a server error in appliaction (you know, this yellow page which should never show up ;) ) - in this error page it shows the message, that the object is renamed or deleted by another user - but that's not wanted. I want a) error label showing the text (same as in server error page) or if that's not working because the displayform is not there b) redirect to a defined error page where I'd add the text. So, what am I missing? Would be great to get an answer!
So, this is my relevant code (I hope so, at least, ask for more if you want :) ):
protected void Page_Load(object sender, EventArgs e)
{
try
{
...
currentEventItem = (SPListItem)SPContext.Current.Item;
...
}
catch (Exception ex)
{
ErrorLabel.Text = "Fehler: " + ex.Message
+ "StackTrace: " +ex.StackTrace;
}
}
and
protected void ButtonRegister_Click(object sender, EventArgs e)
{
try
{
//trying to check if item exists here
SPList eventslist = website.Lists["eventsListString"];
if (eventslist.GetItemById(currentEventItem.ID) != null)
{
bool full = IsFull(registrations, maxRegistrations);
ResetLabel();
if (!full)
{
...
}
else
{
...
}
}
else
{
//tried to redirect the response to an error page
Response.Redirect("ErrorPageString");
}
}
catch (Exception ex)
{
ErrorLabel.Text = "Problem: " + ex.Message
//...(loggingservice)
}
}
So as I thought, the pot. attendee becomes a) redirected to my error page, or b) the catch-block is reached and I get output to my errorlabel (which is in the webpart in top of displayform... maybe that's the problem?) - but all I get is this huge messy error page.
Hope you could help me for I am out of Ideas.
Best regards, Dominik