|
Hmm. If I new what master page was I could tell you. When I deleted " Runat="server" " I didn't receive the error message anymore. Now I have initialize _gdl.VirtualItemCount somewhere because it doesn't like that.
As far as I know VirtualItemCount is a predefined function. When I place my cursor over the function, the tool tip says "Gets or sets the virtual number of items in the System.Web.UI.WebControls.Datagrid control when custom paging is used".
This is the first chunk of code I have after defining the namespace:
public class DataGridPage : Page
{
private int _startIndex=0;
protected DataGrid _gdl;
protected void Page_Load(object Src, EventArgs e)
{
if (!IsPostBack)
{
_gdl.VirtualItemCount = GetItemCount();
_startIndex = _gdl.VirtualItemCount-_gdl.PageSize;
BindGrid();
}
}
Thanks!
Jane
|
|
|
|
|
Hi,
I have a little Generic problem.
Look a this very simplified Composite Pattern:
public abstract class BaseClass
{
}
public class Leaf
{
}
public class LeafA : Leaf
{
}
public class LeafB : Leaf
{
}
public class Composite<TChild> where TChild : BaseClass
{
private List<TChild> _children = new List<TChild>();
public List<TChild> Children { get { return _children;}}
}
Now in the main program I create a sample tree structure:
Composite<BaseClass> root = new Composite<BaseClass>();
root.Children.Add(new LeafB());
root.Children.Add(new LeafA());
Composite<LeafA> comp = new Composite<LeafA>();
comp.Children.Add(new LeafA());
comp.Children.Add(new LeafA());
root.Children.Add(comp);
comp = new Composite<LeafB>();
comp.Children.Add(new LeafB());
comp.Children.Add(new LeafB());
root.Children.Add(comp);
How i can check, if the childnode is a Composite ?
I ever get back a null
foreach (BaseClass b in root.Children)
{
if (b is Leaf)
{
}
else
{
Composite<BaseClass> child = (b as Composite<BaseClass>);
}
}
How I can solve this ?
thx for your help
Roger
|
|
|
|
|
When running my aspx page that uses C# programming I receive the following error message:
Server Error in '/test' Application.
--------------------------------------------------------------------------------
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 50: {
Line 51: conn.Open();
Line 52: count = (int)cmd.ExecuteScalar();
Line 53: }
Line 54: finally { conn.Dispose(); }
Source File: c:\inetpub\wwwroot\test\test.aspx.cs Line: 52
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
test.DataGridPage.GetItemCount() in c:\inetpub\wwwroot\test\test.aspx.cs:52
test.DataGridPage.Page_Load(Object Src, EventArgs e) in c:\inetpub\wwwroot\test\test.aspx.cs:35
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
What can I do so that I won't get this message and can finally see if the data is being loaded into my ASPX page properly? I checked on Microsoft's website to see what it means but it's like reading stereo instructions.
Thanks!
Jane
|
|
|
|
|
Hi there,
IMO, try to delete all file in debug folder and rebuild then the project....
Gud luke
<< >>
|
|
|
|
|
Thanks for the advice but that didn't work. I'm grabbing data from my local SQL server and I just want to post it. Do you need my code?
Jane
|
|
|
|
|
Nevermind, someone else's solution eliminated the problem.
Thanks for your help!!
Jane
|
|
|
|
|
Happy coding ...
<< >>
|
|
|
|
|
change the code on line 52:
count = (int)cmd.ExecuteScalar();
to
count = Convert.ToInt32(cmd.ExecuteScalar());
|
|
|
|
|
Woohooo! That eliminated the error message. Thank you very much! Now I just have to get past another one.
Jane
|
|
|
|
|
Hi..
i have a Class, that has 3 DataMembers, all three are Static...
whenever i try to Serialize her, the output XML is EMPTY!
Please do help,
Here is the Class code, and Xml Serializer code...
The Class
-------
using System;
using System.IO;
using System.Xml;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization ;
namespace ShipurSherut
{
[Serializable]
public class AppSettings
{
public static String Merhav;
public static String Yeud;
public static String ServerAddress;
static AppSettings()
{
}
}
}
The Xml Serializer:
--------------
public static void ToXml(Object objToXml,string filePath,bool includeNameSpace)
{
StreamWriter stWriter=null;
XmlSerializer xmlSerializer;
try
{
xmlSerializer = new XmlSerializer(objToXml.GetType());
stWriter = new StreamWriter(filePath);
if (!includeNameSpace)
{
System.Xml.Serialization.XmlSerializerNamespaces xs= new XmlSerializerNamespaces();
xs.Add("","");//To remove namespace and any other inline information tag
xmlSerializer.Serialize(stWriter, objToXml,xs);
}
else
{
xmlSerializer.Serialize(stWriter, objToXml);
}
}
catch(Exception exception)
{
throw exception;
}
finally
{
if(stWriter!=null) stWriter.Close();
}
}
|
|
|
|
|
If you only have static fields, there is no data in the object, so there is nothing to serialize.
---
b { font-weight: normal; }
|
|
|
|
|
So, Maybe i missunderstood the whole meaning of Static.. i thought a claasic datamembers , let's me , save my data at a class, that don't need and instance in order for me to read the data... a sort of public class. that i can approach from every class in my project./
in that case , i wanted to take the data from my xml file( the application settings) and then use it in multiple classes, without havin the need to open instances of the same class , and double my data....
am i missing the propuse of the static class?
|
|
|
|
|
No, that is correct. The static members reside in the class. But you are serializing an object, not the class.
---
b { font-weight: normal; }
|
|
|
|
|
ok, How can i serialize the class?
|
|
|
|
|
You can't serialize a class, as a class can not be dynamically created.
One way to serialize the static information could be to put the fields in a separate class, and put a static instance of that class in the original class:
public class MyInfo {<br />
string info, moreInfo, excessInfo;<br />
}<br />
<br />
public class MyClass {<br />
static MyInfo info = new MyInfo();<br />
}
Then you can add serialization to the info class, and serialize the static instance.
---
b { font-weight: normal; }
|
|
|
|
|
Man, i can't find the words , to express my gratitude...
i'm programming alone, a messy project.
i got no experiance in c#, and i can't ask anyone i know for help, cause they don't prog... and if they are,, not c#...
anyhow, Thank you... it works FINE! , i did exactly what you told me...
Bye - Yosi!
|
|
|
|
|
Hi All
I am using javascript to catch the browser closing event as I have to delete few files if the user closes the browser directly without logging off.
But if the javascript is disabled in the browser of the user, then files will not get deleted.
Is their anyway I can catch the browser closing event in asp.net rather than javascript?
Thanks
|
|
|
|
|
check this link
http://www.codecomments.com/ASP_.NET_Caching/message670221.html
|
|
|
|
|
hi Albanian
I did check the link. My Page_Unload event is not invoked at all. Is their anyway I can invoke that.
Using javascript I am able to catch the browser closing but I need some way to do without that.
|
|
|
|
|
chinky singh wrote: Is their anyway I can catch the browser closing event in asp.net rather than javascript?
No. The server never knows when the browser window closes, so there is no server side event for that.
If you don't mind waiting for the session to time out, you can catch that event.
However, there is no completely safe method to catch a user going away. If the application thread is recycled, some sessions might be removed without timing out. You will be able to catch almost every user going away, but you should have some code to take care of the occasional one that you can't.
---
b { font-weight: normal; }
|
|
|
|
|
I will ask the question with a 2 step introduction... Please help me.
Step 1: I write an unmanaged DLL in C++. Here is the exported function:
SAMPLEDLL_API void StringAsOUT_AllocatedInDll( char ** szParam )<br />
{<br />
*szParam = new char [ 128 ];<br />
strcpy( *szParam, "Please free my memory after using me!" );<br />
}
Step 2: I write a C# managed EXE to use this DLL
class Imports<br />
{<br />
[DllImport("SampleDLL.dll")]<br />
public static extern void StringAsOUT_AllocatedInDll( ref int szParam );<br />
...<br />
}
...<br />
Imports impObj = new Imports();<br />
int iAddressOfANSIString = 0;<br />
impObj.StringAsOUT_AllocatedInDll( ref iAddressOfANSIString );<br />
string strOUTPUTFromUnmanagedDll = Marshal.PtrToStringAnsi( ( IntPtr ) iAddressOfANSIString );<br />
Console.WriteLine( "Value of strOUTPUTFromUnmanagedDll = {0}", strOUTPUTFromUnmanagedDll );<br />
...
Question: The code works. It does give console output "Value of strOUTPUTFromUnmanagedDll = Please free my memory after using me!"
But isn't there a memory leak? How do I free the memory allocated by new[] inside the unmanaged DLL? All the Marshal class helps artciles always refer to how to free an unmanaged memory block when it is allocated from .NET code. But here it is allocated by unamanaged code. If anybody can please help me with this, I will be grateful.
Thank you!
|
|
|
|
|
http://www.csharpfriends.com/Spec/index.aspx?specID=25.8.htm
|
|
|
|
|
Thanks Albanian. But that really does not answer my question - as you see the article describes how to free the memory only if it was allocated from the C# code.
Like this: You in C#: you allocate some memory in unmanaged heap, and then you free it anfter using it. That is what the article shows.
But my situation is different: I am calling an unmanaged DLL that allocates the memory and returns the pointer. I use it from C#. There is no corresponding call back to the unmanaged DLL that will free the memory. I will have to free it myself from C# after using it.
As I did not allocate it, I don't have the HGlobal Handle or anything - all I have is the address returned. No Marshal class function is helping me out!
Thanks again for seeing my post and replying - I have been waiting for 2 days (i had posted this 2 days ago also) - but nobosy seems to have an answer!
Koushik Biswas
|
|
|
|
|
I mean, simply put, my question becomes: is there a way to call delete[] from C#?
Koushik
|
|
|
|
|
lookup this
http://www.c-sharpcorner.com/Language/PointersInCSharpRVS.asp
|
|
|
|