Creative Commons License
Drekendrop | Blog of Tutorial by Mei Pakpahan is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at drekendrop.blogspot.com.
Permissions beyond the scope of this license may be available at http://softdadesign.co.nr.
Showing posts with label InfoPath. Show all posts
Showing posts with label InfoPath. Show all posts

Tuesday, March 15, 2011

Infopath 2010: Get and Set Value of TextBox Field Using Visual C# onEvent Button Click

I've been working on InfoPath 2010 since a week ago (i'm totally new on it). This was something that i needed to do, and after few hours testing and googling it, finally i could figure out how it works in InfoPath.

1st step---
Right click on your button and choose Button Properties. Click on Edit Form Code... button.


2nd step---
Find the function for the button event. In this case mine is as shown below.
public void updateButton_Clicked(object sender, ClickedEventArgs e)
{
    //write your code here
}

3rd step---
Put this codes below

//scripts to get value of Infopath field

XPathNavigator Period1 = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:period_1", this.NamespaceManager);
String P1 = Period1.Value;

//test if it works
MessageBox.Show(P1 + " " + P2, "Warning", MessageBoxButtons.YesNo);

//scripts to set value of Infopath field        
XPathNavigator P2 = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:period_2", this.NamespaceManager);
P2.SetValue("This is sample of String");


Let's focus on the bold that i highlighted above.
/my:myFields/my:period_1 and /my:myFields/my:period_2, to get this XPath, go back to your InfoPath designer, and right click on the field name at the right sidebar. And choose Copy XPath.


That's all i want to share today. Happy learning!

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Grants For Single Moms