Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,685 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,266 people online right now. Registration is fast and FREE... Join Now!




Custom Server Controls (Asp.net with C#)

 
Reply to this topicStart new topic

Custom Server Controls (Asp.net with C#), stumped

rgfirefly24
post 30 May, 2008 - 09:23 AM
Post #1


D.I.C Regular

Group Icon
Joined: 7 Apr, 2008
Posts: 330



Thanked 5 times

Dream Kudos: 150
My Contributions


ok so i have a custom server control created. Only thing is...... I have no idea how to get the image to actually display

Problem:

Take the captcha(shown in C# tutorials) and make it into a custom server control.

I replaced Session variables with view states sense Session variables don't work in server controls, and i create the captcha just fine and save it as Captcha.jpeg.


Main question in the Render Controls is there something that works with displaying images? (I am extending Image for this) and if so what exactly needs to happen for it to display? i've searched through the msdn site and every site i can find on the System.Web.UI.WebControls.Image class and just cannot figure it out.
User is offlineProfile CardPM

Go to the top of the page

Jayman
post 30 May, 2008 - 01:19 PM
Post #2


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,839



Thanked 38 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


When you say "custom server control", do you mean a Web User Control?
User is offlineProfile CardPM

Go to the top of the page

rgfirefly24
post 30 May, 2008 - 05:08 PM
Post #3


D.I.C Regular

Group Icon
Joined: 7 Apr, 2008
Posts: 330



Thanked 5 times

Dream Kudos: 150
My Contributions


QUOTE(jayman9 @ 30 May, 2008 - 02:19 PM) *

When you say "custom server control", do you mean a Web User Control?


no an actual server control

different from a user control


Custom server control vs Custom user control

Also there are so many tutorials out there on creating custom server controls but none of them really touch on dealing with dynamically created images.

This post has been edited by rgfirefly24: 30 May, 2008 - 05:10 PM
User is offlineProfile CardPM

Go to the top of the page

Jayman
post 30 May, 2008 - 06:12 PM
Post #4


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,839



Thanked 38 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


Can you post the code for the custom control?
User is offlineProfile CardPM

Go to the top of the page

rgfirefly24
post 30 May, 2008 - 07:03 PM
Post #5


D.I.C Regular

Group Icon
Joined: 7 Apr, 2008
Posts: 330



Thanked 5 times

Dream Kudos: 150
My Contributions


QUOTE(jayman9 @ 30 May, 2008 - 07:12 PM) *

Can you post the code for the custom control?



i'll have to do it when i get back to work on monday.. Totally spaced my mind to post what i've got so far lol.

my main question is, though. If i use

CODE


bmp.save("Captcha", ImageFormat.Jpeg);



will that create an image that i can store in cache and call at a later time or does that just set the stage for the image.
User is offlineProfile CardPM

Go to the top of the page

Jayman
post 31 May, 2008 - 08:00 AM
Post #6


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,839



Thanked 38 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


Actually, that will save the image to your hard drive in the JPEG format. If that was your intention, then you have it correct.

However, if you want to store it in memory, then use a MemoryStream object.

CODE

MemoryStream memStream = new MemoryStream();
bmp.save(memStream , ImageFormat.Jpeg);


Now it is stored in memory and can be passed using a byte array to your web page.

An example can be found here.
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 31 May, 2008 - 08:04 AM
Post #7


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


You can also save the image to the pages current output stream (which is the way I do it with items such as this), like this


csharp

bmp.Save(System.Web.HttpContext.Current.Response.OutputStream, ImageFormat.Jpeg);



I'll write a short tutorial on this hopefully this weekend, on doing this with an HTTPHandler, which is what you're going to want to do with a CAPTCHA type setup
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 31 May, 2008 - 09:52 AM
Post #8


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Well I felt productive so I got that tutorial written. It's kind of long, and lots of it wont apply to you, but I think it will definitely shine a new light on this whole CAPTCHA issue for you.


Working with images via HttpHandlers
User is offlineProfile CardPM

Go to the top of the page

rgfirefly24
post 31 May, 2008 - 11:59 AM
Post #9


D.I.C Regular

Group Icon
Joined: 7 Apr, 2008
Posts: 330



Thanked 5 times

Dream Kudos: 150
My Contributions


QUOTE(PsychoCoder @ 31 May, 2008 - 10:52 AM) *

Well I felt productive so I got that tutorial written. It's kind of long, and lots of it wont apply to you, but I think it will definitely shine a new light on this whole CAPTCHA issue for you.


Working with images via HttpHandlers



thanks guys. My knowledge of C# is more basic than a baby with his first rattle. I was basically thrown on this project like a kid being thrown into water.

I'll be going over your tutorial psycho probably 100 times smile.gif thank you to everyone that has or will help me with my C# whoas. smile.gif

User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:16AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month