Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Redirecting to another page from an eventhandler ItmAdded event

  Asked By: Salina    Date: Nov 20    Category: Sharepoint    Views: 4555

I am trying to redirect to a page in a layout folder after data is added to my
list. However the Httpcontext.current is null in an eventhandler.

So my code looks like: Could anyone tell me what I need to do to get this
working ?

public override void ItemAdded(SPItemEventProperties properties)
{

base.ItemAdded(properties);
SPListItem item = properties.ListItem;
try
{
current = HttpContext.Current;
DisableEventFiring();
string EmployeeType = item["Employee Type"].ToString();
int RecordId = ARBA_HR.DataLayer.RecordAccess.SaveNewCase(EmployeeType);

item["Title"] = RecordId.ToString();
item.Update();
string strNewresiractionUrl =
"~site/_layouts/ARBA_HR.ApplicationPages/DocumentUpload.aspx?TrimRecordId=" +
RecordId;
//
http://542301-opti:30869/sites/ARBA/_layouts/ARBA_HR.ApplicationPages/DocumentUp\
load.aspx"
SPUtility.Redirect(strNewresiractionUrl, SPRedirectFlags.Trusted, current);
(
EnableEventFiring();

}
catch(Exception ex )
{

}
finally
{

}

}

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Amareswar Karkera     Answered On: Nov 20

Event Handlers are fired by the system and aren't guaranteed to have a context.
This is particularly true of "after" event  handlers that are run asynchronously.
I've never tried it, but you could try doing this with the ItemAdding event and
see if the result is different.

 
Answer #2    Answered By: Cheyenne Jacobson     Answered On: Nov 20

Declare current  as a global variable and initialize it in Constructor of
your event  handler. Don't initialize it in method.

Class urHandlerClass : ..

{

HttpContext current;

Public urHandlerClass()

{

current = HttpContext.Current;

}

public override  void ItemAdded(SPItemEventProperties properties)
{

// use 'current' here
}

}



 
Answer #3    Answered By: Makayla Lewis     Answered On: Nov 20

I had tried this and Http.context is still null. I was able to do it with
itemAdding instead.

 
Answer #4    Answered By: Miranda Scott     Answered On: Nov 20

I managed to do it with itemAdding.

 




Tagged: