|
Echilon wrote: I'm really stuck on this and I'd appreciate any help.
Hello Echilon and welcome to code project. You posted this problem yesterday and I replied to you. Now you start a new thread of the same subject without ever responding to my reply. That is considered rude and an abuse of the CodeProject resources.
Take a moment to read these posting guidelines[^] along with the first post in this forum titled "How to get an answer to your question".
led mike
|
|
|
|
|
So, the first attempt ended up in the wrong board, so I'm asking again here (hopefully the right board):
I'd like to add an existing Webusercontrol (.ascx) programatically to a class which returns a Webcontrol:
public class ClassName :IHoldtheDefinition
private WebControl AddName()
{
WebControl cntrl = new WbControl();
cntrl.Controls.Add(new Label() {Text="test"});
wuc_anything wuc = new wuc_anything(); //existing Webusercontrol inside the Assembly
cntrl.Controls.Add(wuc);
return wuc;
}
It doesn't throw an exception, but the content is not displayed.
Why I need it this way? I get the class just by it's name (implements an interface) and want to give the possibility to add content to a page by three simple steps.
1. Add the button definition to a xmlfile
2. add a class witch is named as defined in the xml file - the class has to implement the interface and returns a Webcontrol
3. If needed design a WebUserControl and add it programatically to the class as described above.
Help would be apreciated.
|
|
|
|
|
ezazazel wrote: So, the first attempt ended up in the wrong board, so I'm asking again here (hopefully the right board):
Never mind. Albeit it is an ASP.NET question but it figures under C#, the one thing to appreciate is your immediate response by posting it in a more near forum.
A few quick clarifications regarding your snippet:
ezazazel wrote: AddName
If you are invoking through an ASPX page through <% %> function, the exception might just get swallowed. Did you try encompassing the code in a try-catch and from within a CodeBehind. An attached debugger can help you flag out if control has any issues trying to enter the catch block.
ezazazel wrote: IHoldtheDefinition
Were there any warnings thrown during compilation regarding this?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
I think I located the problem. It seems to be here:
WebControl cntrl = new WebControl
(HtmlTextWriterTag.Div);<---
I tried HtmlTextWriterTag.Object /Unknown and many more.. sometimes I get a blank square, but most of the time nothing.
With the debugger taken a closer look, it reveals to me, that the control is correctly added. It is simply not shown (rendered).
WebUserControl1 wuc = new WebUserControl1();
cntrl.Controls.Add(wuc);
return cntrl;
Here the very essential part of the code, where WebUserControl1 holds a Label:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AddCntrlCls cls = new AddCntrlCls();
try
{
this.Controls.Add(cls.AddElement());
}
catch(Exception ex)
{
throw new Exception(ex.ToString());
}
}
}
public class AddCntrlCls
{
public WebControl AddElement()
{
WebControl cntrl = new WebControl(HtmlTextWriterTag.Div);
WebUserControl1 wuc = new WebUserControl1();
cntrl.Controls.Add(wuc);
return cntrl;
}
}
Yes, before I forget - I'm working with a project (WebApplication), therefore I can create instances of Controls, at least to me it ssems so.
|
|
|
|
|
Ah, I finally found a way. Thought too much in C# and not enough in ASP.NET
Here's the way it works:
public class AddCntrlCls : System.Web.UI.Page //Has to inherit from Page
{
public WebControl AddElement()
{
WebControl cntrl = new WebControl(HtmlTextWriterTag.Div);
cntrl.Controls.Add((Control)Page.LoadControl("WebUserControl1.ascx")); //Here is the Magic
cntrl.Controls.Add(new Label() { Text = "I'm a Text" });
return cntrl;
}
}
|
|
|
|
|
i'm working with SQL Server 2005
in my c# App i've got a DataGridView that is bound to a Source(a table in the database)
i can add new row ,delete row but CAN'T Update row Content
this is the code :
this is the event when a buttoncell is clicekd
<br />
private void dgvCarDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)<br />
{<br />
switch (e.ColumnIndex)<br />
{<br />
case 8:<br />
UpdateDataSet();<br />
break;<br />
case 9:<br />
dS_CarManager.T_CarDetails.Rows[e.RowIndex].Delete();<br />
UpdateDataSet();<br />
break;<br />
}<br />
}<br />
<br />
this functions operate as a service function to update<br />
private void UpdateDataSet()<br />
{<br />
TA_CarDetails.Update(dS_CarManager.T_CarDetails);<br />
dS_CarManager.T_CarDetails.AcceptChanges();<br />
}<br />
<br />
<br />
<br />
<br />
Have Fun
Never forget it
|
|
|
|
|
Hello everybody! I have this API published in a C DLL:
int readValue(int objectId, int outputTypeId, void * buf);
Where buf is a pointer to a buffer in memory that can be pretty much anything, depending on the outputTypeId value. In the simplest cases, it points to an int or to a float.
The managed declaration I'm using is:
[DllImport(ReferenceDLL)]<br />
public static extern int H5Aread(int attr_id, int mem_type_id, IntPtr buf);
I have googled a lot and came out with the following solution to get the right value out of that call:
public int GetValueInt32()
{
int value = 0;
GCHandle handleValue = GCHandle.Alloc(value, GCHandleType.Pinned);
DllImports.H5Aread(ObjectId, ImportedDataTypes.H5T_NATIVE_INT, handleValue.AddrOfPinnedObject());
value = (int)handleValue.Target;
handleValue.Free();
return value;
}
public float GetValueFloat()
{
float value = 0;
GCHandle handleValue = GCHandle.Alloc(value, GCHandleType.Pinned);
DllImports.H5Aread(ObjectId, ImportedDataTypes.H5T_NATIVE_FLOAT, handleValue.AddrOfPinnedObject());
value = (float) handleValue.Target;
handleValue.Free();
return value;
}
It works, but I'm a bit puzzled. According to my understanding of how GCHandle should work, it shouldn't be necessary to copy the value of handleValue.Target into value - it's just pinning the address of value to avoid moving. But if omit the copying step, value is always zero.
If this is the way GCHandle is supposed to work, then why I'm passing an instance of value to GCHandle.Alloc instead of the memory size to allocate?
If anyone can shed more light on this topic, I'd be really grateful. My next project is going to use a lot of P/Invokes, and I really need to understand what's going on there.
Is there's a "right" way to accomplish what I'm trying to do?
Luca
The Price of Freedom is Eternal Vigilance. -- Wing Commander IV
En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur.
(But the best thing God has created, is a New Day.)
-- Sigur Ròs - Viðrar vel til loftárása
|
|
|
|
|
Luca Leonardo Scorcia wrote: Is there's a "right" way to accomplish what I'm trying to do?
I don't know. But from my perspective as a C++ developer I would almost never use PInvoke. I would use a C++/CLI mixed mode class library project to solve all the managed-to-native issues. The resulting assembly would provide a managed class solution for use in C#.
But that's me
led mike
|
|
|
|
|
Hi Luca,
I have used GCHandle many times to pass a reference type from managed C# to unmanaged C code;
I never needed GCHandle.Target since my object was either an instance of a class I created,
or a simple array. What really gets passed on is a memory pointer, pointing to the
managed data (which got pinned down so the GC cannot move it around any more), so the
unmanaged world can manipulate the data in the managed object.
I assume you need GCHandle.Target to get the same result when you pass on a value type
(such as the int and float in your examples); but I cannot confirm that from experience,
and I have never come across any example of GCHandle.Target till now.
However, when you know the argument is a value type, you can declare another prototype
of your unmanaged method using the ref or out keyword, and forget all about GCHandle:
reffing/outing a local value type is OK, since locals are on stack, and stack does not get
moved around, so the following should work:
[DllImport(" ... .dll")]
public static extern void H5Aread(... , out float val);
public int GetValueInt32(){
int value = 0;
DllImports.H5Aread(ObjectId, ImportedDataTypes.H5T_NATIVE_INT, out value);
return value;}
The hearth of the matter is you can overload the method, i.e. have multiple managed method
prototypes with different parameter signatures, but all pointing to the same unmanaged
function.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Whoa! This is great news! I didn't think about overloading the method!
The distinction about value types and reference types makes sense. I'll do a few more tests in the evening to understand everything better, but your post shed much more light on this topic. Thanks a lot!
Luca
The Price of Freedom is Eternal Vigilance. -- Wing Commander IV
En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur.
(But the best thing God has created, is a New Day.)
-- Sigur Ròs - Viðrar vel til loftárása
|
|
|
|
|
Hi Luca,
GCHandle provides direct conversion to IntPtr (use: GCHandle.ToIntPtr() )
God bless,
Ernest Laurentin
|
|
|
|
|
I am having a problem with with printing from .Net 2.0 on HP LaserJet 1010 printers.
Occasionally (sometimes once a month, sometimes once a day) printer gets 'blocked' in such a manner that it can not print anything from .net 2.0.
When printDocument.print method is invoked, it throws InvalidPrinterException, even if printer has just been selected from printDialog. Printer is online and working (everything else can be printed on it), only printing that goes through .net is blocked. The problem seems that printer name is not recognised even if it is returned by PrintDialog, and printDocument.PrinterSettings.IsValid is false.
Even a simple example like this doesn't work:
printDialog1.Document = printDocument1;
printDialog1.ShowDialog();
// after printer gets blocked, isValid is allways 'false'
if (printDocument1.PrinterSettings.IsValid)
printDocument1.Print();
else
MessageBox.Show("Error!");
The way to 'unblock' the printer is to simply change its name (printers and faxes / right click on printer / rename) or reinstall the printer. After that printer gets unblocked and works for some time until it gets blocked again (while it is 'blocked', it can still print from other programs, only .net programs are blocked). This only happens with HP LaserJet 1010 and 1018 printers. All the other printers work perfectly. On some computers these printers get occasionally blocked, while on some computers printers work perfectly. Printers are installed with newest drivers, .net is 2.0 with service pack and computer operator works as an administrator for a local machine.
Any idea why this blocking is occuring?
Tnx in advance
Dragan Matic
|
|
|
|
|
Hey peeps
I need a tutorial for crystal reports, i found a few here but they either don't compile or they use generated code(which i intend to avoid)
Can anyone recommend a GOOD article for a reporting noob?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
|
If you're expecting someone to provide you with a complete solution, you've come to the wrong place. No one is going to just do your work for you. Hopefully as a developer you realize this.
You can use the System.IO.Directory.GetFiles method to get a list of files at/below a particular path. Use File.Copy to copy a file. File.Exists can be used to check for the presence of a particular file.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Thanks for your GREAT ADVICE and answer.
|
|
|
|
|
That better not be sarcasm.
My current favourite word is: Nipple!
-SK Genius
|
|
|
|
|
Krishnaraj Barvathaya B wrote: Thanks for your GREAT ADVICE and answer.
I like to give people the advice they deserve. In this case, I believe you got what was coming to you.
If you're not happy with my answer, maybe you should consider whether you asked the right question.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Recurse through the directories and look for files in them. It's pretty simple to do.
|
|
|
|
|
i have successfully deployed Sql Reports in server.I am able to view those reports with browsers but not from my c#.net windows application.If i access reports with browsers for first time then only i am able to access those reports in my c#.net windows application. plz help me on this issue.
let me know if u have any questions on this issue
Thanks&Regards
Vinay
|
|
|
|
|
How are we supposed to help you if you don't provide details of what the problem is?
Or are we supposed to guess?
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
How about more elaborate details as to what your problem is?
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
Hello everyone,
I'm making a program, but I'm (obviously) stuck with a problem.
I want to write a message to the current topscreen through a C# application.
For instance: when you open Microsoft Word and you type 'hello' it will double the word like this 'hheelllloo'.
The application allready knows when a key is pushed, now the only thing that will have to be done is write a message to the current top window (like word or notepad or whatever window is open and where you are typing in).
I guess that this is possible with something like PostMessage and GetTopWindow. But it won't work. Can anybody tell me what I'm doing wrong? Or can someone tell me what will work?
Thank you allready.
This is what I have:
[DllImport("user32.dll")]
public static extern int GetTopWindow(int hwnd);
[DllImport("user32.dll")]
public static extern int PostMessage(int hWnd, uint Msg, int wParam, uint lParam);
const int VK_KEY = 0x41;
const int WM_CHAR = 0x0102;
int WindowToFind = GetTopWindow(0);
Console.WriteLine(WindowToFind);
int result = PostMessage(WindowToFind, WM_CHAR, VK_KEY, 0);
Console.WriteLine(result);
The output for result is always 1.
The output for WindowToFind is different, sometimes it gives the same value at different windows. Sometimes a different value. One of the outcome of WindowToFind is 131138
edit:
Allright... finaly I found out the anwser to my problem (after hours of searching :P).
I just had to use the SendKeys class.
SendKeys.SendWait("<value>");
</value>
modified on Wednesday, March 5, 2008 5:42 AM
|
|
|
|
|
maybe GetDlgItem and GetWindowText or SetWindowText can help ?
just an idea.
|
|
|
|
|
Hi,
Am trying to implement a progress bar in an application to copy files/folders. This progress bar is meant to sho the staus of copy.
Can anyone clarify:
1. What's the appropriate method for this to implement an actual status update using progress bar?
2. Whenever I put those two threads running (Main thread and progress bar) it seems the main thread is hanged until files are copied and the progress bar is updated once the copy process is over.
I came to know that, this can be sorted out in .NET2.0 using BackgroundWorker class but what can I do for this in .NET 1.1?
Regards,
Panicker.
modified on Wednesday, March 5, 2008 5:13 AM
|
|
|
|
|