Can you pass two Values in preEdit in ASP.Net?

Can you pass two Values in preEdit in ASP.Net?

HgooberHgoober Posts: 11Questions: 3Answers: 0

Is is it possible to to pass two Values in preEdit? Currently I have

editor.PreEdit += (sender, e) => 
                        editor.Field("EmpNumber").SetValue(e.Values["FirstName"]);

But I would like for it to combine the location number with the first name. So it would be 257Joe I am hoping I could do

editor.PreEdit += (sender, e) => 
                        editor.Field("Name").SetValue(e.Values["LocationNumber"]+["FirstName"]);

or something like that.

thank you

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Almost exactly that - you just need to use e.Values again for ["FirstName"]:

    e.Values["LocationNumber"]+e.Values["FirstName"]
    

    Assuming FirstName is in the submitted data of course.

    Allan

  • HgooberHgoober Posts: 11Questions: 3Answers: 0

    I was getting the error "Operator '+' cannot be applied to operands of type object and object." Then I changed the code to

    editor.PreEdit += (sender, e) => editor.Field("EmpNumber")SetValue(e.Values["LocationNumber"].ToString()+e.Values["FirstName"]ToString());
    
    

    Now it works perfectly. Thanks Allan for pointing me in the right direction.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Ah yes - because the submitted data can be more or less anything, it is of the generic object type. Adding a casting method such as ToString() will do the job nicely.

    Allan

This discussion has been closed.