|
Hi,
I have created a windows application in CSharp that is using a web browser control.
When i did some coding to handle a chat window an exception was thrown with the following message:
"COM object that has been separated from its underlying RCW can not be used"
The chat browser window is constantly updating its content automatically.
My question is how can i work around this problem?
I appreciate any help you can give me.
Yours sincerely
Andla
|
|
|
|
|
I have several different tables with textboxes
I want user fill out some information into those boxes and after hit save, I
want to store all those values from those textboxes into database
I don't know why after I hit button save, all the values are gone. Pleaes
tell me how i can keep those values? We
Thanks
|
|
|
|
|
Is that ASP.NET? So you should post it there.
I think you have to set AutoPostback property to false for those textboxes.
Mazy
No sig. available now.
|
|
|
|
|
Set EnableViewState to true and in the server event handler for the "Save" button (or whatever you call it), gather the values from each TextBox and save them to a database using ADO.NET. Search the CodeProject web site for examples. There's also several examples of inserting data into a database from ASP.NET using ADO.NET. For example, if you have a couple TextBox es on the page and a button with the Client event handler save_Click , you could do something like the following:
private void save_Click(object sender, EventArgs e)
{
if (!IsValid) return;
SqlConnection conn = new SqlConnection("...");
SqlCommand cmd = conn.CreateCommand();
cmd.CommentText = "INSERT INTO Table1 (FirstName, LastName) " +
"VALUES (@FirstName, @LastName)";
cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 40).Value = textBox1.Text;
cmd.Parameters.Add("@LastName", SqlDbType.NVarChar, 40).Value = textBox2.Text;
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
DisplayError(e.Message);
}
finally
{
conn.Close();
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for posting.
I really appreciate your time. My problem here is a littl bit different. All those textboxes are creating during running time. Tables (or datagrids not bond from data),
are an array of tables (or datagrids).
I fill all those datagrids(tables) into a place holder.
I'm really frustrated now. I just created another version which does not use datagrid. I use Table of Web Control, everything seemed work fine until I started collecting data. Fromdate, todate have textboxes for user to enter values. I have a submit button, I don't know why everytime I hit button, all the values are gone. My best guess is whenever i hit the button the application has to postback, therefore my array of datagrids(or web tables) are NULL.
Is there a way that I can collect data from these tables (remember these tables are also dynamically change; hence I need help so much, I never built any programatic talbes like these before)
Month fromdate todate Values
Month1
Month2
Month3
Month4
Month5
Month6
Month7
Month8
Month9
Month10
Month11
Month12
--------------------------------------------------------------------------------
|
|
|
|
|
First of all, in order to get values from dynamically generated controls you can either follow the steps I'll discuss after this, or use Request.QueryString for GET requests, Request.Forms for POST requests, or Request.Params if you don't care which HTTP method the parameters come through. Since each is a collection, you can either enumerate all the values and sort out what is what using the names and values, or access the values using the name (like Request.Params["Month1"] ).
Second, in order to keep the controls on the page, you must make sure that in Page_Load you are not clearing the controls or re-binding them when you don't want to by using the IsPostBack property. On the first request to the page, this property is false so bind any data / generate controls. If a user submits the page form, this property is true so skip all that stuff, but only if you've set EnableViewState for the page and other controls to true (which is the default).
For more information, see Page.EnableViewState Property[^] (includes example), Page.IsPostBack Property[^] (includes example), and a nice little article that should help tie them all together, Taking a Bite out of ASP.NET ViewState[^].
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Is there a way to add methods with a wizard. For instance, if I drop a button on the form, double click on the button the code....(assuming the button name is calculate)
private void calculate_Click(object sender, System.EventArgs e)
How can I add other methods like when the mouse moves over it or when the button gets the focus. VC++ 6.0 had a wizard to add event handlers.... what does C# have?
Thanks
Ralph
|
|
|
|
|
There isn't such a thing in C#. You can add other handlers through property grid for the controls.
Mazy
No sig. available now.
|
|
|
|
|
Errm, there are plently ways to do it. AddIns, that VB script thing they have, and if you want more you can go thru the VSIP SDK.
mazy.PostCount--;
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
leppie wrote:
mazy.PostCount--;
He said about wizard that exist in VC6.0. I haven't seen it in C#. There is property dialog there that do it,as other CPains said. Am I wrong?
Mazy
No sig. available now.
|
|
|
|
|
Select the control you want to add the method, press F4 to get the property window for that control. On the top of the property window, there is a button with a lightnigbolt in it, click it. No you have all the events fired by that control. Double click on the event you want and the code will be written on the file.
Free your mind...
|
|
|
|
|
Hello,
i'm having difficulties to use a multidimensional array of pointers in C#. The objective would be to have an array of pointer (2D) using the type TestClass. Here is the example test code that doesn't work:
public class MainClass
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
unsafe
{
TestClass obj = new TestClass(2);
TestClass *[,] ptrArray = new TestClass *[2,2];
ptrArray[1,1] = &obj;
ptrArray[1,1]->Display();
}
}
}
public class TestClass
{
private int data;
public TestClass (int d) { data = d; }
public void Display() { Console.WriteLine(data.ToString()); }
}
The following error is encountered:
Cannot take the address or size of a variable of a managed type.
Thanks for helping.
|
|
|
|
|
You dont have to use the pointer notation, that will automatically create it. If u wanna use the pointer notation , I think u need to use a struct rather.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Thx for your reply. Are you sure it does not copy the object, because i'm developping a system that will instanciate huge amount of objects and i couldn't afford to increase the memory allocated.
thanks, regards.
|
|
|
|
|
if the object is a class then each slot will be instantiated to null. with structs (as u probably know, or can guess by now) will be zero and thus the full size allocated.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Every object is a reference type (allocated on the heap) and each Type that derives from ValueType (which derives from Object but is handled differently by the CLR) is a value type, hence is allocated on the stack. An Array - even if it contains value types - is a reference type. If it contains reference types, the memory overhead is negligible. So, at least you don't need to use an unsafe pointer for the array.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
OK thanks for those comments, it really helped me.
regards.
|
|
|
|
|
Work only with value type and only 1D array.
Example:
using System;
namespace TestUnsafe
{
public class Test
{
[STAThread]
static void Main(string[] args)
{
// Reference type
Console.WriteLine("With a reference type");
TestClass [,] tcArray = new TestClass [2,2];
tcArray[0,1] = new TestClass(2);
tcArray[1,1] = new TestClass(4);
tcArray[1,1].Display();
tcArray[0,1].Display();
// Value type
TestStruct obj = new TestStruct(3);
TestStruct obj2 = new TestStruct(6);
Console.WriteLine("With a value type");
unsafe
{
TestStruct * myObj = &obj; // Value Types only
myObj->Display();
}
Console.WriteLine("With a value type 1D array");
unsafe
{
TestStruct * [] ptrArray = new TestStruct * [3]; // 1D Array only
ptrArray[0] = &obj;
ptrArray[2] = &obj2;
ptrArray[2]->Display();
Console.WriteLine("Loop in the 1D Array");
foreach (TestStruct * ptr in ptrArray)
{
if (ptr != null)
ptr->Display();
}
}
Console.WriteLine("With a value type Jagged Array");
unsafe
{
TestStruct * [][] ptrJaggedArray = new TestStruct * [2][];
ptrJaggedArray[0] = new TestStruct * [2];
ptrJaggedArray[1] = new TestStruct * [2];
ptrJaggedArray[1][1] = &obj;
ptrJaggedArray[1][1]->Display();
Console.WriteLine("Loop in the Jagged Array");
foreach (TestStruct * [] ptrArray2 in ptrJaggedArray)
{
foreach (TestStruct * ptr in ptrArray2)
{
if (ptr != null)
ptr->Display();
}
}
}
}
}
public class TestClass
{
private int data;
public TestClass (int d) { data = d; }
public void Display() { Console.WriteLine(data.ToString()); }
}
public struct TestStruct
{
private int data;
public TestStruct(int d) { data = d; }
public void Display() { Console.WriteLine(data.ToString()); }
}
}
|
|
|
|
|
Hi!
I am developing a web application in asp.net using C# code with sql server 2000 as a db server. I take input from user an populate it in db.now i have problem when i try to insert data in db.
my code is as follows:
SqlConnection myConnection;
private void Page_Load(object sender, System.EventArgs e)
{
myConnection = new SqlConnection("Server=AKRAM;uid=sa;pwd=mypwd;database=HRIS");
Label1.Text="";
}
private void btnSubmit_Click(object sender, System.EventArgs e)
{
String strInsert = "insert into User(UserID,Password,UserType,"+
" FirstName,LastName,Age,Gender,Phone,Fax,Email,URL,"+
" Address,City,State,Country) values (@UserID," +
" @Password, @UserType, @FirstName, @LastName, @Age, " +
" @Gender, @Phone, @Fax, @Email, @URL, @Address, @City, @State," +
" @Country)";
SqlCommand insCommand = new SqlCommand(strInsert, myConnection);
// Create new parameters for the SqlCommand object and
// initialize them to the input-form field values.
insCommand.Parameters.Add(new SqlParameter("@UserID", SqlDbType.VarChar, 20));
insCommand.Parameters["@UserID"].Value = txtID.Text;
insCommand.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 20));
insCommand.Parameters["@Password"].Value = txtPassword.Text;
and so on i provide values to the parameters.
insCommand.Connection.Open()
but following stament comes, error is generated:
insCommand.ExecuteNonQuery();
..
..
..
I m unable to figure out the problem. Can any body help me...
Waiting 4 reply..
|
|
|
|
|
Wrap your insCommand.ExecuteNonQuery(); in a try/catch block and catch the SqlException that gets throw. What does that say?
- Nick Parker My Blog
|
|
|
|
|
Change this...
String strInsert = "insert into User(UserID,Password,UserType,"+
" FirstName,LastName,Age,Gender,Phone,Fax,Email,URL,"+
" Address,City,State,Country) values (@UserID," +
" @Password, @UserType, @FirstName, @LastName, @Age, " +
" @Gender, @Phone, @Fax, @Email, @URL, @Address, @City, @State," +
" @Country)";
Into this..
String strInsert = "insert into User(UserID,Password,UserType,"+
" FirstName,LastName,Age,Gender,Phone,Fax,Email,URL,"+
" Address,City,State,Country) values (?,?,?,?,?,?,?,?,?,?)";
But I'm not sure if this will work, because you are only passing 2 parameters. Do some test with only 2 paramaters... e.g.
String strInsert = "insert into User(UserID,Password) values ?,?)";
Free your mind...
|
|
|
|
|
instead of insCommand.Connection.Open() use
myConnection.Open() and check whether all the server details are correct or not. then try to pass hardcoded values in the query instead of parameters. If it works fine then go to parameters
|
|
|
|
|
Hi Everyone,
I have a problem with a set of components I am creating. Basically I have the following:
Menu : Component<br />
MenuItemCollection : CollectionBase<br />
MenuItem : Component
MenuItemCollectionDesigner
The Menu and MenuItems contain a MenuItemCollection with the following attributes against it
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Editor(typeof(Design.MenuItemCollectionDesigner), typeof(System.Drawing.Design.UITypeEditor))
The designer opens a new form which adds/removes the menu items into the menu/menuitem in a tree style ui.
The items get added ok and are correctly written the InitializeComponent function on the form. The first problem is the fact that the designer does not write out the AddRange call for each MenuItemCollection so the menu items never get added to the collection.
The second problem (the first problem also occured before I introduced this one!) I dont want the menu items to be visible at designtime in the pane on the bottom of the desiger so I added:
[DesignTimeVisible(false), ToolboxItem(false)]
I cant figure out how to delete the items from the code when the parent menu is removed?
I have googled till my fingers bleed, I have seen other peoples similar problems but not really any answer to whats going on with the AddRange method.
One thing I did notice - I Have a custom grid with a custom column collection, the AddRange member for that also stopped working, it did work at 1 point during development, but now both controls dont write out the AddRagne command.
Can anyone help me?
Thanks - James
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
As far as removing all the child components recursively when their parent is removed, get the IComponentChangeService service in your designer and handle the ComponentRemoving or ComponentRemoved event. You can recurse through your children and remove them. The designer should reflect this automatically.
As far as adding the components, use a good disassembler (like ildasm.exe that comes with the .NET Framework SDK) or a good decompiler like .NET Reflector[^] and perhaps take a look at how the existing Microsoft.VisualStudio.WindowsForms.MenuDesigner, Microsoft.VisualStudio designer does it.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the reply.
I am downloading the .NET Reflector for a bit of research - thanks for the link.
The other two problems are now sorted.
1) Everything was working fine apart from the fact I was missing the Add call to the collection myself. I was just adding the new component into the Container collection thinking that was sufficient - Doh!
2) I just did a recursive dispose on the Diposing function on the Component and cleared the collections at the end and that solved that one.
Thanks - James
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|