|
It would work, but you're putting an extra burden on the client and server to encrypt communications to send the control(s). It may be negligible, however, so it really is up to your implementation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi
I have a problem which I think is basically due to my lack of understanding as to the order that events are processed.
I have an .aspx page to which I want to programtically add all its controls (so that I can change the look of the application by simply modifying a couple of classes). I've based this on Peter Provost's article "ASP.Net Templates - Using Inheritance" (http://www.codeproject.com/aspnet/page_templates.asp).
The code almost works except that not all of my controls get added to my form as intended - the earlier-added ones do, the later-added ones do not. This is the kind of rendered HTML I get:
<div><label for="txt4">4</label><input name="txt4" id="txt4" type="text" /></div>
<div><label for="txt5">5</label><input name="txt5" id="txt5" type="text" /></div>
<form name="frmApp" method="post" action="company.aspx" id="frmApp">
<input type="hidden" name="__VIEWSTATE" value="dDw1MzgxOzs+kxSQNMEmk8WT5ck725Xa7SNOEg4=" />
<div><label for="txt0">0</label><input name="txt0" id="txt0" type="text" /></div>
<div><label for="txt1">1</label><input name="txt1" id="txt1" type="text" /></div>
<div><label for="txt2">2</label><input name="txt2" id="txt2" type="text" /></div>
<div><label for="txt3">3</label><input name="txt3" id="txt3" type="text" /></div>
</form>
My guess is that this is because the later-added controls have not been correctly initialised before the page is rendered.
Can anyone enlighten me?
Many thanks in advance.
Gary
==============
The .aspx file
==============
<%@ Page Inherits="CompanyPage" Src="classes/company_page.cs" %>
====================
The Code-behind file
====================
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using MyNamespace;
public class CompanyPage : MyNamespace.ExtendedPage{
//--------------------------------------------------------------------------------------------------
protected override void OnInit(System.EventArgs e){
for(int i = 0; i < 10; i++){
//add some text boxes and labels to the page
this.AddTextBox("Text" + i, "txt" + i);
}
base.OnInit(e);
}
//--------------------------------------------------------------------------------------------------
}
===========================
The Base Classes (compiled)
===========================
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
namespace MyNamespace{
public class BasicPage : System.Web.UI.Page{
//--------------------------------------------------------------------------------------------------
protected String Footer{
get{
return("...</body></html>");
}
}
//--------------------------------------------------------------------------------------------------
protected String Header{
get{
return("<html><head>...");
}
}
//--------------------------------------------------------------------------------------------------
}
public class ExtendedPage : BasicPage{
//--------------------------------------------------------------------------------------------------
protected void AddTextBox(String strLabel, String strName){
this.Controls.Add(new LiteralControl("<div>"));
this.Controls.Add(new LiteralControl("<label for=\"" + strName + "\">" + strLabel + "</label>"));
HtmlInputText ctrl = new HtmlInputText();
ctrl.ID = strName;
this.Controls.Add(ctrl);
this.Controls.Add(new LiteralControl("</div>\n"));
}
//--------------------------------------------------------------------------------------------------
private void AddExistingControls(HtmlForm form){
//****************************************************
// Add existing controls to form and remove from class
//****************************************************
for(int i = 0; i < this.Controls.Count; i++){
//get first control in collection
System.Web.UI.Control ctrl = this.Controls[0];
//add control to form
form.Controls.Add(ctrl);
//remove control (gets added back along with form in BuildPage)
this.Controls.Remove(ctrl);
}
}
//--------------------------------------------------------------------------------------------------
protected void BuildPage(HtmlForm form){
//***************
// Build the page
//***************
//this.Controls.Clear();
//add page header
this.Controls.AddAt(0, new LiteralControl(Header));
//add form
this.Controls.Add(form);
//add page footer
this.Controls.Add(new LiteralControl(Footer));
}
//--------------------------------------------------------------------------------------------------
private HtmlForm GetForm(){
//********************************************************
// Returns HtmlForm containing controls added to sub-class
//********************************************************
HtmlForm form = new HtmlForm();
form.ID = "frmApp";
//objects passed by reference!
AddExistingControls(form);
return form;
}
//--------------------------------------------------------------------------------------------------
protected override void OnInit(System.EventArgs e){
BuildPage(GetForm());
base.OnInit(e);
}
//--------------------------------------------------------------------------------------------------
}
}
|
|
|
|
|
Questions about ASP.NET should be posted in the ASP.NET[^] forum, regardless of what language they're written in (ASP.NET has more to do with a class library that works the same for any source language than a particular language).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi, i am new to C#.
I have a problem in using threads.
In my application i have two forms ( formA and formB )
In formA, there is a method "display" to display ( creating an object of formB and calling its show method )the formB.
and there is thread in formA, which monitors an integer variable continuosly, and when ever it set to 1, it calls the display method.
and there is a button in formA, upon clicking calls the same display method.
Clicking the button in formA , causes formB to load without any problem
But the same display method called by the thread in formA, doen't display the formB ( form "not responding" is coming in the text of formB ).
Can any one help me out in solving this problem ?
M.V.Ravikumar.
|
|
|
|
|
You have to execute your display method in the main UI Thread to avoid such problems.
This can be achieved by using the Invoke or BeginInvoke method of your FormA.
www.troschuetz.de
|
|
|
|
|
Thank you for your response.
It solved my problem.
M.V.Ravikumar
|
|
|
|
|
I want to break the API function (waitcommevent)
where I'm waiting data which i expect to receive.
the waitcommevent function is operating in a thread.
after a specific time if there's no data comes i make
thread.abort() methode to exit the thread.
but the waitcommevent is still hanging up the com
so when i try to close the com i can't.
so first I want to break the waitcommevent but i can't.
th1 = new Thread(new ThreadStart (loop));
timer1.Enabled = true ;
th1.Start() ;
void loop ()
{
while (true)
{
err = WaitCommEvent (handle,this.evPtr,IntPtr.Zero);
if (err==false)
{
error = Marshal.GetLastWin32Error() ;
if (error == ERROR_IO_PENDING) MessageBox.Show("ERROR_IO_PENDING"); else MessageBox.Show(error.ToString()) ;
}
else
{
this.getMask = (uint) Marshal.ReadInt32(this.evPtr);
if ( (getMask&1) == 1 )
{
err = ReadFile(handle,byt,1,out h,IntPtr.Zero) ;
MessageBox.Show(error.ToString());
MessageBox.Show("first byte:"+byt[0].ToString());
MessageBox.Show("Second byte:"+byt[1].ToString());
}
}
}
}
private void timer1_Tick(object sender, System.EventArgs e)
{
bool error = CancelIo(handle) ;
MessageBox.Show("Cancel is :"+error.ToString());
th1.Abort();
error = CloseHandle(handle) ;
MessageBox.Show("Handle closed is :"+error.ToString()) ;
}
|
|
|
|
|
can i transmit text from navigate of axwebBrowser to textbox?
|
|
|
|
|
Yes, but you have to create an interop assembly for MSHTML. If you installed VS.NET, the Microsoft.mshtml.dll assembly should already be present. If not, just run:
tlbimp.exe /out:Interop.MSHTML.dll MSHTML.dll You must get a reference to the IHTMLDocument2 interface. Handle the WebBrowser control's OnNavigationComplete (something like that - don't remember exactly right off-hand) and in that handler cast the AxWebBrowser 's Document property to IHTMLDocument2 . From there you can enumerate the elements or find the element with the ID you want, then set its value property (since it's an <input type="text"> element).
There are some articles about this here on CodeProject. A search[^] on "WebBrowser IHTMLDocument2" yields several good articles.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi
thanks for your reply.
i have a textbox that cannt chang selected font and forcolor of text in it and i want insert image to it.thus i use from html and show it in webbrowser and then i want transmit content of webbrowser to a textbox in another form.
textBox.selectedtext=<html<ui+textbox.selectedtext+ ui="">/HTML>.
.....
please tell me
can i do this work?how?
please suggest a realated sample.
|
|
|
|
|
That's terribly inefficient. The RichTextBox already supports all that - changing the selected font, etc.
As I mentioned before (and you continue to waste performance and memory on such a large solution using the WebBrowser control), you enumerate the IHTMLElement s from the IHTMLDocument2.all collection. When you find the elements you want, concat the text:
string str = string.Empty;
foreach (IHTMLElement2 elem in doc.all)
{
IHTMLInputElement input = elem as IHTMLInputElement;
if (elem != null) str += input.value;
} This is untested, but should give you an idea of how to concat text from text boxes. You should refer to the MSHTML reference to know how else to do things. Anything you can do in scripting you can do with MSHTML and more.
Read the MSHTML Reference[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i want opendialog .i need name of file only no directory of it in filename.
how i do?
|
|
|
|
|
Take a look at the Path class which provides some methods to deal with path strings. Think the GetFileName or the GetFileNameWithoutExtension method should do the job.
www.troschuetz.de
|
|
|
|
|
|
i have to use textbox.becouse i want transmit content of this textbox to another textbox in another form.
|
|
|
|
|
i have to use textbox.becouse i want transmit content of this textbox to another textbox in another form.
i think that i should use from html but i dont know how?
|
|
|
|
|
The TextBox control doesn't support different fonts in the same TextBox. It's all one font or nothing. You can't change the font of a selection in a TextBox. Also, a TextBox control doesn't know how anything about HTML...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
We've a component that uses "osql.exe" to run an installation script and get a bunch of datbase objects (tables, triggers, stored proc...etc) installed on SQL Server. Is there something we can use with Oracle and MySQL to perform this same task? Thanks.
Norman Fung
|
|
|
|
|
They both have their own command-line applications. MySQL's is simply mysql.exe, but I don't know what Oracle's is. I would suggest either looking it up with google or find an Oracle newsgroup.
Might I recommend a better alternative, though? Nothing gaurantees that those command shells will be resolvable (in fact, IIRC, mysql.exe is not - it's in a directory that is not in the PATH env. var.). A better way might be to use a connection to their master databases (might have different names for each major database, but for SQL Server it is called "master") and then use whatever IDbCommand implementations that are appropriate for the database you're accessing (like SqlCommand , OleDbCommand , etc.) to build database objects. This is a pretty typical solution and doesn't rely upon command shells that may or may not exist.
Another scenario is if you're building database objects on a remote machine. The local machine may not the database installed so the command shell won't be present anywhere on the local machine.
For this reason, we use the method I outlined to build and update SQL Server databases, which should work just fine with any other RDBMS.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath. We have our own script runner which does this, but thing is, it doesn't handle certain situations well. For instance, comment block - while we can take out the commments, it makes the scripts a hell lot harder to read and to maintain.
|
|
|
|
|
HI~
I would like to ask
How do I change the data in C++ dll by a C# program?
I have ever tried this.
I wrote a dll with VC++. There is a variable in the dll (e.g "m_string"). "m_string" is a LPCTSTR type and it's inital value set by constructor is _T("Hello World"). I also wrote a function for setting the variable. The function is declared like this:
extern "C" _declspec(dllexport) void set(LPCTSTR s)
{
m_string = s;
}
Afterward, I wrote a C# dll assembly. The C# dll import the dll written by C++. The import the dll like this:
#region DLLImports
[DllImport("Test.dll")] //test is the C++ dll filename
private static extern void Set(string s);
#endregion
Finally, I wrote a form to call the method "Set". After the method have finished executing, the value "m_string" does not change. The "m_string" is still "Hello World".
My question is, how to change a variable in dll permanently by a C# library or exe?
Thanks
|
|
|
|
|
First of all, using LPTSTR or LPCTSTR uses an ANSI or Unicode string depending on whether or not the UNICODE (or sometimes _UNICODE) symbol is defined. Unicode is only natively supported on Windows NT (4.0, 2000, XP, 2003, and all newer versions). So, you need to change your declaration like so:
[DllImport("Test.dll", CharSet=CharSet.Auto)]
private static extern void set(string s); Also notice how set uses a lower-case "s"? Your method signatures have to match (minus the "A" or "W" at the end, if you do that for different sigs for different platforms) character-for-character and case-for-case, otherwise you have to set the actual function name to P/Invoke in the DllImportAttribute 's EntryPoint field in the attributed P/Invoke method.
Finally, make sure that Test.dll is in the same directory as the executing process (not just the same as the assembly that uses it) or in another directory specified in your PATH environment variables. Native executables use this to find DLLs (and other executable files) at runtime, so the Test.dll must be resolved.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
HI~
I am sure the function work properly.
My situation is that
The dll is loaded will windows startup. The dll is used to so a string on the screen when the windows startup. The string is a variable of the dll. When the dll is loaded, a WM_PAINT message is sent and the OnPaint function is called. The OnPaint function draw the window and text on the screen. I would like to use C# program to make changes to the string so that the screen can show different string dynamically.
I use the code above and try to achieve this result. However, the variable within the extern function is changed but after the function is complete, the string on the screen still not been changed.
So, how to achieve the correct result?
Thanks~
|
|
|
|
|
Changing the variable is not enough. You have to invalidate the client area in your unmanaged DLL so that when the WM_PAINT message is called the invalidated region is redrawn. In your OnPaint handler, get the string value and draw it on the screen.
There are many ways to invalidate a region in C/C++, and since I'm guessing that you're using MFC (judging by the OnPaint event), you can use Invalidate or InvalidateRect , both inheritted from CWnd .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes
The dll will send a message to itself every 2 or 3 second call a function. The function is written by me, which use to check whether the variable have been changed or not. If there is any variable change, the function will return true, otherwise, it will return false. If true is returned, a refresh message will be sent to the dll and force to redraw the screen. However, the screen is refreshed by the variable which shown on the screen still not changed.
I think that there may be a solution. There is a handle for the variable. First, the C# program call the extern function of the unmanaged dll and return the handle of the variable to C#. And then C# program use this handle and pass it to the extern function of the unmanaged dll as argument and call it to set the variable value. However, I do not know the unmanaged dll code well.
Can anyone tell me how to solve it?
Thanks
|
|
|
|