Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2005, 04:07 PM
kmi kmi is offline
Registered User
 
Join Date: Mar 2005
Location: Medellin, Antioquia, Colombia.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default here is the code

here's the code for the last posting!! :) if you correct it please let me know!! thanks in advance!!!

using System;
using System.Web;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;


namespace Cohete.HttpInputFileReloaded
{
    [DefaultProperty("Text"),ToolboxData("<{0}:HttpInpu tFileReloaded runat=server></{0}:HttpInputFileReloaded>")]
    public class HttpInputFileReloaded : System.Web.UI.WebControls.WebControl,INamingContai ner
    {
        public TextBox txtRuta = new TextBox();
        public ImageButton imgBtn = new ImageButton();
        public HtmlInputFile inpFile = new HtmlInputFile();

        [Category("Appearance"), Description("Clase para el TextBox")]
        public string TextBoxClass
        {
            get
            {
                EnsureChildControls();
                return txtRuta.CssClass;
            }
            set
            {
                EnsureChildControls();
                txtRuta.CssClass = value;
            }
        }
        [Category("Data"), Description("Archivo a transferir al servidor")]
        public HttpPostedFile PostedFile
        {
            get
            {
                if (inpFile.PostedFile.InputStream.Length != 0)
                {
                    return inpFile.PostedFile;
                }
                else
                {
                    return null;
                }
            }
        }
        [EditorAttribute(typeof(System.Web.UI.Design.UrlEdi tor), typeof(System.Drawing.Design.UITypeEditor)),
        Category("Appearance"), Description("Ruta en la que se encuentra la imagen del boton")]
        public string RutaImagen
        {
            get
            {
                EnsureChildControls();
                return imgBtn.ImageUrl;

            }
            set
            {
                EnsureChildControls();
                imgBtn.ImageUrl = value;
            }
        }

        protected override void CreateChildControls()
        {
            txtRuta.ID = "txtRuta";
            txtRuta.ReadOnly = true;
            txtRuta.Enabled = false;
            Controls.Add(txtRuta);
            inpFile.ID = "inpFile";
            inpFile.Attributes.Add("style","display:none");
            inpFile.EnableViewState = true;
            Controls.Add(inpFile);
            imgBtn.ID = "imgBtn";
            Controls.Add(imgBtn);
        }

        protected override void OnPreRender(EventArgs e)
        {
            if(!this.Page.IsClientScriptBlockRegistered("HtmlI nputFileCode"))
            {
                string strScript = "<script language=\"JavaScript\" type=\"text/javascript\">" +
                    "function HandleFileButtonClick(InputName,TextName)" +
                    "{" +
                    " document.getElementById(InputName).click(); " +
                    " document.getElementById(TextName).value = document.getElementById(InputName).value; " +
                    "} " +
                    "</script>";
                this.Page.RegisterClientScriptBlock("HtmlInputFile Code",strScript);
            }
            imgBtn.Attributes.Add("OnClick","javascript:Handle FileButtonClick('" + this.ID + "_" + this.inpFile.ID + "','" + this.ID + "_" + this.txtRuta.ID + "');");
        }

        protected override object SaveViewState()
        {
            EnsureChildControls();
            object[] state = new object[2];
            object objBase = base.SaveViewState();
            state[0] = objBase;
            state[1] = txtRuta.Text; ;
            return state;
        }

        protected override void LoadViewState(object savedState)
        {
            object[] state = (object[])savedState;
            base.LoadViewState (state[0]);
            EnsureChildControls();
            txtRuta.Text = state[1].ToString();
        }

        public void SaveAs(string FileWithPath)
        {
            if (inpFile.PostedFile.InputStream.Length != 0)
            {
                inpFile.PostedFile.SaveAs(FileWithPath);
            }
        }
    }
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM
disable forum code within [code] blocks? nikolai Forum and Wrox.com Feedback 0 October 23rd, 2003 07:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.