Was my field empty

A

Albator

Hi,

I have some probleme with managed C# code!

What I wan't to do on is on onbeforechange event test if the value of
the field was empty I make an action if not I don't wan't to do that!

my code:
[InfoPathEventHandler(MatchPath="/ns1:Case/ns1:Geschaeft/ns1:Notizen/ns1:Notiz",
EventType=InfoPathEventType.OnBeforeChange)]
public void Notiz_OnBeforeChange(DataDOMEvent e)
{
if
(thisXDocument.DOM.selectSingleNode("/ns1:Case/ns1:Geschaeft/ns1:Notizen/ns1:Notiz").text
== "")
{
thisXDocument.DOM.selectSingleNode("/ns1:Case/ns1:Geschaeft/ns1:Notizen/ns1:Notiz/@Eintrag").text=
DateTime.Now.ToString();}
}

The probleme is if I make this condition the result is never true!

How I can do?

Thanks for your help
 
F

Franck Dauché

Hi,

To get to your value, try to use e.Source instead (use the event). Also, it
is better to test for length = 0 than to test for "".

Hope that it helps.

Regards,

Franck Dauché
 
A

Albator

Hi Frank,

Thanks for your answer!

But If I take e.source in a onafterchange or a onbeforechange event:

my field is empty I enter somethings the event fire and in e.source I
have the data that I have entered!

So How to know that this field was empty? has a poperty in e.source
that i haven't seen?

Thanks for your help
 
F

Franck Dauché

Hi,

Then if you need to know what was the value, you can use: e.OldValue.
If you want to know if it was blank before your change, you can use:
e.OldValue.ToString().Length to see it it was 0.

Hope that it helps.

Regards,

Franck Dauché
 
A

Albator

Hi,

Thanks a lot for this answer it's very helpful I don't have seen this
method yesterday!

Problem solve!

Thanks

++
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top