|
Actually here's the sample code which I have difficulty for..
<asp:repeater id="someRepID" runat="server">
<ItemTemplate>
<asp:Panel ID="somePanelID" runat="server"></asp:panel>
</ItemTemplate>
</asp:repeater>
Now Panel is suppose to contain 2 type of template.
Template 1:- (gif/jpg images)
<a href=".."><img src=".."></a>
Template 2:- (swf flash images)
<object ...><value src="..">..</object>
And those two template is determine by a bit column. so I know which to display.
Now, with the above sample code, I got the Panel displaying when i put it outside of the repeater block. But when it's inside it doesn't work. Sorry if this is in the wrong forum, because code-behind language is c#. Any help appreciated....
|
|
|
|
|
The best way is to not use the Panel in the FCL, but instead to extend it with your own class and in your override to Render do something similar to what I posted before. There are ways to do this using ASP-style syntax but it's cludgy and you have little control over it.
So, you could either define properties in your derivative class which would be set by data-binding expressions by the parent control (like <%# DataBinder.Eval(Container.DataItem, "flash") %> ) or have your derivative class get the current data item, which I can't remember how to do off-hand (the answer's in the .NET Framework SDK, though).. Once you get that bit you need, just conditionally output the string as you have above in your override for the Render method.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a client using HttpWebRequest to send a POST request to a Web service. Using a TCP sniffer, I can see that the last character is truncated, making the web service wait for the missing last character until it times out. Here is the code:
HttpWebResponse authResponse = null;
StreamReader responseStreamReader = null;
try
{
byte[] requestBytes = Encoding.UTF8.GetBytes(this.txtRequest.Text);
HttpWebRequest authRequest = (HttpWebRequest)WebRequest.Create(new Uri(this.txtAuthURI.Text));
authRequest.Method = "POST";
authRequest.Credentials = CredentialCache.DefaultCredentials;
authRequest.ContentType = "text/xml";
authRequest.ContentLength = requestBytes.Length;
Stream requestStream = authRequest.GetRequestStream();
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Flush();
requestStream.Close();
authResponse = (HttpWebResponse)authRequest.GetResponse();
responseStreamReader = new StreamReader(authResponse.GetResponseStream());
StringBuilder sb = new StringBuilder();
sb.AppendFormat("HTTP Status: {0}{1}", authResponse.StatusCode, Environment.NewLine);
this.txtResponse.Text = sb.ToString();
}
catch (Exception ex)
{
MessageBox.Show(this, "Cannot send Auth Request: " + ex.GetType().ToString() + ": " + ex.Message);
}
finally
{
if (null != responseStreamReader)
{
responseStreamReader.Close();
}
if (null != authResponse)
{
authResponse.Close();
}
}
I have tried using a StreamWriter, to no avail. Does anyone have an idea of what is wrong here?
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Buffering the entire content can lead to problems. Try using smaller buffers (4096 is typically a good buffer size) and getting bytes and writing to the request stream in a loop till all bytes are sent. I've seen similar problems like this with such a large buffer (and there were some limits in older TCP/IP implementations in Windows, but I don't know if these apply now). I do find it weird that it's just the last character, though. Using a smaller buffer is definitely worth a try, though.
Out of curiousity, why not just create a Web Service proxy (either using VS.NET to generate it from WSDL, which also gives you async capabilities, or deriving manually from HttpWebClientProtocol or SoapHttpClientProtocol depending on your service implementation and your requirements)?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have been coding a media player for a school project with GDI+ and C#. My app displays alot of bitmaps to change the colors of the player (eye candy). If I have another app window open (ex. Calculator) on top of my player and I move the calculator around, my player window draws really slow and the remnants of the calculator window are displayed over the bitmaps for a short period before a complete refresh. My mem usage for the player is always around 30M - 50M which seems like alot to me for an app that can only change skin textures. My OnPaint creates a bitmap to draw to before refreshing the screen.
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
Image screen = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);<br />
Graphics graphics = e.Graphics;<br />
Graphics temp = Graphics.FromImage(screen);<br />
<br />
GraphicsPath texturePath = new GraphicsPath(new Point[] {new Point(30, 50),
new Point(30, 50),<br />
new Point(30, 30),<br />
new Point(50, 30),<br />
new Point((this.Right - this.Left) - 20, 30), <br />
new Point((this.Right - this.Left) - 20, 30),<br />
new Point(this.Right - this.Left, 30),<br />
new Point(this.Right - this.Left, 50),<br />
new Point(this.Right - this.Left, (this.Bottom - this.Top) - 20),<br />
new Point(this.Right - this.Left, this.Bottom - this.Top - 20),<br />
new Point(this.Right - this.Left, this.Bottom - this.Top),<br />
new Point((this.Right - this.Left) - 20, this.Bottom - this.Top),<br />
new Point(50, this.Bottom - this.Top),<br />
new Point(50, this.Bottom - this.Top),<br />
new Point(30, this.Bottom - this.Top),<br />
new Point(30, (this.Bottom - this.Top) - 20),<br />
new Point(30, 50)},<br />
new byte[] {(byte)PathPointType.Start, <br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier, <br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier, <br />
(byte)PathPointType.Line, <br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line});
<br />
GraphicsPath navButtonsPath = new GraphicsPath(new Point[] {new Point(this.panel1.Left, this.panel1.Top),<br />
new Point(60, this.panel1.Top),<br />
new Point(60, this.panel1.Top),<br />
new Point(50, this.panel1.Top),<br />
new Point(50, this.panel1.Top + 10),<br />
new Point(50, this.panel1.Top + 90),<br />
new Point(50, this.panel1.Top + 90),<br />
new Point(50, this.panel1.Top + 100),<br />
new Point(60, this.panel1.Top + 100),<br />
new Point(this.panel1.Left, this.panel1.Top + 100),<br />
new Point(this.panel1.Left, this.panel1.Top + 110),<br />
new Point(60, this.panel1.Top + 110),<br />
new Point(60, this.panel1.Top + 110),<br />
new Point(50, this.panel1.Top + 110),<br />
new Point(50, this.panel1.Top + 120),<br />
new Point(50, this.panel1.Top + 200),<br />
new Point(50, this.panel1.Top + 200),<br />
new Point(50, this.panel1.Top + 210),<br />
new Point(60, this.panel1.Top + 210),<br />
new Point(this.panel1.Left, this.panel1.Top + 210)},<br />
new byte[] {(byte)PathPointType.Start,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line});<br />
<br />
Brush tBrush = new TextureBrush(background);<br />
<br />
temp.FillRectangle(new LinearGradientBrush(<br />
new Point(0, 0), new Point(this.Right - this.Left, 0), Color.SlateGray, Color.WhiteSmoke), this.ClientRectangle);<br />
<br />
temp.FillPath(tBrush, texturePath);<br />
temp.DrawPath(new Pen(<br />
new LinearGradientBrush(<br />
new Point(30, 30), new Point(this.Right - this.Left, this.Bottom - this.Top), Color.WhiteSmoke, Color.SlateGray), 3.5F), texturePath);<br />
temp.FillPath(new LinearGradientBrush(<br />
new Point(50, this.panel1.Top), new Point(this.panel1.Left, this.panel1.Top), Color.WhiteSmoke, Color.CadetBlue), navButtonsPath);<br />
temp.DrawPath(Pens.Black, navButtonsPath);<br />
<br />
graphics.DrawImage(screen, ClientRectangle);<br />
<br />
temp.Dispose();<br />
navButtonsPath.Dispose();<br />
texturePath.Dispose();<br />
screen.Dispose();<br />
}
any help on resolving these issues is appreciated.
|
|
|
|
|
Good to see that you're disposing your objects when done with them!
One thing you should take into account is the PaintEventArgs.ClipRectangle . This is the region that needs to be repainted. It may add some additional logic to your code, but if done decently should improve your performance. Also, cache what you can. If you use a particular brush you've created over and over again, store it in a field instead of creating it each time.
Also, enable double-bufferring if you haven't already to avoid flicker. The easiest way is to call the following in your constructor:
SetStyle(
ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer |
ControlStyles.UserPaint,
true); See the documentation for the Control.SetStyle in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for the quick response Heath...
I've got my app running at around 19M...
Funny thing if I minimize the window then restore the app uses around 5M consistently. Is there an explanation for this?
|
|
|
|
|
You'd better explain yourself a little more, or I'm afraid you won't get a useful answer. What's the situation? You already know how to get substrings, so can you use that method to get your substrings, and use the method you use for getting chars to get chars??? Is it not okay for you (from a performance perspective) to get one-length substrings?
Regards,
Jeff Varszegi
|
|
|
|
|
I'm not sure if i totally understand your question. You begin by asking if it is possible to split a string into substrings and chars. You then proceed by saying that you understand how to do this.
Here's an example, hopefully it will help:
string myString = "this is an example string";<br />
<br />
string mySub = myString.Substring(startIndex, length);
<br />
char myChar = myString[index];
If this doesn't answer your question, maybe try reposting so it's a little more clear.
|
|
|
|
|
Or simply "asdf".ToCharArray() (see the String.ToCharArray method documentation in the .NET Framework SDK). You can also enumerate a String by its chars. If you want to enumerate Unicode code points, see the TextInfo documentation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hey guys, can any1 please tell me wtf is wrong with the following code :
private void panelRightView_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
System.Drawing.Graphics oGfx = this.panelRightView.CreateGraphics();
System.Drawing.Rectangle rect = this.picTitleBar.Bounds;
oGfx.DrawLine(_penLine, rect.Right, rect.Bottom, this.panelRightView.ClientSize.Width - rect.Right, rect.Bottom);
}
The scenario is like this: I've two panels on my Windows form panelLeftView (LEFT docking) and panelRightView (FILL docking). In my right panel's PAINT event handler, I need to draw a f@#king line. The line draws ok, works exactly as I want, it expands when I increase the width of the form, but the problem is that this code doesn't work if I decrease the width of the form . The line previously drawn is not cleared when i reduce the form width. Can any .Net guru (especially of C#) tell me why is this happening? Am I doing something wrong ? Or is that problem occuring only to remind me that I'm working on Microsoft's technology where nothing seems to work as expected ???
Please Help.
Thanks
Gurmeet S. Kochar If you believe in God, it's because of the Devil
My CodeProject Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|
When resizing the form , you NEED to redraw the control, otherwise it will only display what is in the video memory. My terminology is probably not 100% accurate, but all you really need to know is that you need to refresh your form, and it will work.
just do:
this.refresh();
|
|
|
|
|
|
BTW, I'm issuing this.panelRightView.CreateGraphics() instead of e.Graphics because in the latter case, the line only draw once and then doesn't expand at all when form's width is increased. I dunno the reason but ....
Gurmeet S. Kochar If you believe in God, it's because of the Devil
My CodeProject Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|
You need to force the control to refresh when resized and DO NOT create a new Graphics object in the Paint event handler. Besides, even if you do, you must call Graphics.Dispose on it or you're going to find your memory consumption increasing and performance decreasing.
To force your control to repaint itself when it resizes, you can do this a number of ways. The easiest is just to call SetStyle(ControlStyles.ResizeRedraw, true); in your constructor. You could also set the protected ResizeRedraw property to true in your constructor. These result in the same effect.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Besides, even if you do, you must call Graphics.Dispose on it or you're going to find your memory consumption increasing and performance decreasing
Hey, what about that Garbage Collection thing?
Heath Stewart wrote:
To force your control to repaint itself when it resizes, you can do this a number of ways
Well, I tried using SetStyle but it says
"Cannot access protected member 'System.Windows.Forms.Control.SetStyle(System.Windows.Forms.ControlStyles, bool)' via a qualifier of type 'Panel'; the qualifier must be of type 'FormPackages' (or derived from it)".
Gurmeet S. Kochar If you believe in God, it's because of the Devil
My CodeProject Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|
Gurmeet S. Kochar wrote:
Hey, what about that Garbage Collection thing?
The Graphics class - like many other class in the .NET FCL - use native resources (unmanaged) so the GC cannot collect them. Read Programming for Garbage Collection[^] in the .NET Framework SDK to learn more.
Gurmeet S. Kochar wrote:
Well, I tried using SetStyle but it says...
As I mentioned, you should call this in your constructor - the constructor for the control you're writing, which means you must extend the base class you want and add it to your constructor:
public class MyPanel : Panel
{
public MyPanel()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer
| ControlStyles.UserPaint, true);
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Only a short question,
is there a chance to splitting a string into substrings and chars?
I have no idea how to make this. To split a string in substrings it's clear to me, also to make a string to chars... but how could i split substrings and chars from one string?
If you want realize your dreams, you shouldn't sleep!
|
|
|
|
|
Hi All,
I am writing a code to transmit data from a client to a server using sockets. The first data transmitted from the client to the server gets transmitted, after that I get a error when I attempt to send a 2nd set of data. It says "Operation not allowed on non-connected sockets". Part of my code is
Client Code:
private void TcpDataSendTransmitter()
{
/*This is line which is giving me the error*/
networkStream = tcpClientListner.GetStream();
streamWriter = new System.IO.StreamWriter(networkStream);
streamReader = new System.IO.StreamReader(networkStream);
try
{
string temp = txtData.Text;
streamWriter.WriteLine(temp);
streamWriter.Flush();
listBoxClient.Items.Add(temp);
}
.
.
.
}
Server code:
if(clientSocketListener.Connected)
{
NetworkStream networkStream = new NetworkStream(clientSocketListener);
System.IO.StreamWriter streamWriter = new System.IO.StreamWriter (networkStream);
System.IO.StreamReader streamReader = new System.IO.StreamReader(networkStream);
streamWriter.WriteLine("Server: Your Are Connected");
streamWriter.Flush();
temp = streamReader.ReadLine().ToString();
listBoxServer.Items.Add(temp);
}
What could be the possible Solution for this.
Regards
Tarakeshwar
|
|
|
|
|
Judging by the exception message, your client or server has disconnected. Look through your code and 1) make sure your code is tolerant in such cases, since this is something you really can't control (either one could loose their connection at any time, and 2) that you are closing your connection prematurely. I see nothing of the sort in your sample code, but it could easily exist elsewhere in your code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yeah I went through the Code, I think the problem is in my server Code. I have been trying to debug it. The problem is I have initialised the connection in the Connect Button. So only for the first instance when I connect using the button the connection exist. After that the server is not in the listening mode as the event is in the connect button. I will have to initialise my tcp Connection and the thread outside the button click event. That should hopefully solve the problem.
Tarakeshwar
MCSE(Security), CCIE Q(Routing and Switching)
|
|
|
|
|
If your TCP socket connection variable (TcpListener or whatever you're using) is declared in the event handler, then it will be garbage collected when it goes out of scope (and when the GC gets around to it). You need to at least declare it outside of your event handler, just like buttons, text boxes, and other UI components are declared as fields and initialized in a method.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
did a program that lists stats for creatures that will combat each other. Need some help to clone this object for the users desired number of fighters and then each winner will combat the other winner until there is one winner.
i am new to this stuff. hope i am not asking to much or even if it is bad manners or anything.
|
|
|
|
|
If you're new to .NET development, why don't you start creating simple applications and reading the vast number of articles on .NET development (with C#, VB.NET, and other languages) on sites like CodeProject?
If you want to write an application, this is not the place for help to write an entire application. This forum - and pretty much any other forum you'll ever find - are for specific problems or questions, not to help you write an application from scratch. That requires actually knowing something about programming, and only you can discover that.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I agree with what you said, but I sometimes think that OOP would be a good topic for a discussion board. Did anyone ever suggest that?
Regards,
Jeff Varszegi
|
|
|
|
|