1
Answer

Wrong value from TextBox within a UserControl

Administrator

Administrator

22y
1.4k
1
Yet another problem regarding usercontrols! I thought that using usercontrols would be so great and easy, but it turns out to be rather difficult I think. Anyway, I have a page with three usercontrols. One with a bunch of TextBoxes, another with a submit button and the third with a DropDownList (autopostback = true). When you select something from the dropdown, the textboxes in the second usercontrol will be get values from a database. NOW, if I change the values in the textboxes (after they have been filled with data) and hit the submit button in the third usercontrol, I only get the original values from the textboxes and not the new one I typed in. I have tried the following codes: Page1 oP1 = (Page1)LoadControl("Page1.ascx"); oP1 = (Page1)Page.FindControl("oPage1"); Response.Write(oP1.JobAppliedFor); oText = new TextBox(); oText = (TextBox)this.Parent.FindControl("oTextJobAppliedFor"); Response.Write(oText.Text); // property Response.Write(oP1.oTextJobAppliedFor.Text); // public textbox They all return the original value. So how the heck am I suppose to get the NEW value?? I am very confused and will be utterly happy if someone could help me out!! Thanks!
Answers (1)
0
John Arcadella

John Arcadella

NA 345 226.5k 20y
Hi Josh, I think you would find the following article by Paul DiLascia useful: http://msdn.microsoft.com/msdnmag/issues/03/02/CQA/default.aspx Hope this help, MCB.
0
jmales

jmales

NA 5 0 20y
OK, I'll try to explain. I have an unmanaged C++ library that works with a piece of hardware. I wrote a managed C++ wrapper for the library. My main app is in C#. The hardware (library) raises an event in the unmanaged C++ . I want to call a routine in the GUI (C#). To do that I send a delegate from the C# program to the c++ program. The managed C++ wrapper gives me the ability to declare a reference in the C# program. I do not want to declare routines in external dll's. The delegate is called. That part works. The problem is that I can't get the C++ to pass the whole array over to the C#. Only the first element in the array seems to arrive. I once had this defined as unsafe code, and passed a *byte instead of []byte - and it worked. I was just trying to make this code safe. Hope this explains my intentions. Thanks for all your patience. Josh
0
bilnaad

bilnaad

NA 686 0 20y
For the record are talking C# or C++ here ^_^
0
jmales

jmales

NA 5 0 20y
Thanks, but I already got it to work with unsafe code. This is how it looked: typedef void __stdcall FoundPidFunction ( unsigned char *pData, } However, I want it to work with safe code. Am I asking too much from MS? Josh
0
bilnaad

bilnaad

NA 686 0 20y
maybe it's easier to use unsafe code. Let the unmanaged function return a pointer to the first byte in the array. Let that function take a parameter in wich to store the length of the array. Then you could use unsafe C# code to get the byte array. int length; byte* ptr = UnmanagedFunction(&length); byte[] bytes = new bytes[length]; for(int i = 0; i < length; i++) { bytes[i] = *(ptr+i); }