Click here to Skip to main content
15,897,704 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionSaving the Uploaded File to the Web Server!! Pin
Sr...Frank2-Sep-09 3:44
Sr...Frank2-Sep-09 3:44 
AnswerRe: Saving the Uploaded File to the Web Server!! Pin
Blikkies2-Sep-09 4:19
professionalBlikkies2-Sep-09 4:19 
GeneralRe: Saving the Uploaded File to the Web Server!! Pin
Sr...Frank2-Sep-09 4:29
Sr...Frank2-Sep-09 4:29 
GeneralRe: Saving the Uploaded File to the Web Server!! Pin
Abhijit Jana2-Sep-09 4:33
professionalAbhijit Jana2-Sep-09 4:33 
GeneralRe: Saving the Uploaded File to the Web Server!! Pin
Blikkies2-Sep-09 4:36
professionalBlikkies2-Sep-09 4:36 
GeneralRe: Saving the Uploaded File to the Web Server!! Pin
Abhijit Jana2-Sep-09 4:42
professionalAbhijit Jana2-Sep-09 4:42 
AnswerRe: Saving the Uploaded File to the Web Server!! Pin
Abhijit Jana2-Sep-09 4:32
professionalAbhijit Jana2-Sep-09 4:32 
Questionhow to set property for a user control from cs file Pin
ansriharsha2-Sep-09 1:24
ansriharsha2-Sep-09 1:24 
Hi ,
i have created a user control numberbox which is working fine .
But i want set the property value from aspx.cs file dynamically which is not possible . it is taking the value from toolboxdata table only even though i set the property in page load.

numberbox code:

using System.Collections.Generic;
using System.Text;
using System;
using System.Web.UI;
using System.ComponentModel;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

namespace ERP.Controls
{
    /// <summary>
    /// Number Box ASP.NET control
    /// </summary>
    [
    ToolboxData("<{0}:NumBox runat=server></{0}:NumBox>"),
    DefaultProperty("DecimalPlaces")
    ]
    
    public class NumBox : TextBox
    {

        private int mDecimalPlaces = 0;
        private char mDecimalSymbol = '.';
        private bool mAllowNegatives = true;

        /// <summary>
        /// Gets or sets the number of decimals for the number box.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(typeof(int), "2"),
        Description("Indicates the number of decimal places to display.")
        ]
        public virtual int DecimalPlaces
        {
            get { return mDecimalPlaces; }
            set { mDecimalPlaces = value; }
        }


        



        /// <summary>
        /// Gets or sets the digit grouping symbol for the number box.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue("."),
        Description("The digit grouping symbol.")
        ]

        public virtual char DecimalSymbol
        {
            get { return mDecimalSymbol; }
            set { mDecimalSymbol = value; }
        }

        /// <summary>
        /// Gets or sets wheter negative numbers are allowed in the number box.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(true),
        Description("True when negative values are allowed")
        ]
        public virtual bool AllowNegatives
        {
            get { return mAllowNegatives; }
            set { mAllowNegatives = value; }
        }



        /// <summary>
        /// Gets or sets the value of the number box.
        /// </summary>
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(0),
        Description("Indicates the number of decimal places to display.")
        ]

        public virtual double Value
        {
            get
            {
                try
                {
                    return ParseStringToDouble(this.Text);
                }
                catch (FormatException e)
                {
                    throw new
                    InvalidOperationException("NumberBox does not contain a valid Number.");
                }
                catch (Exception e)
                {
                    throw e;
                }

            }
            set
            {

                if ((value < 0) & !AllowNegatives)
                    throw new
                    ArgumentOutOfRangeException("Only positive values are allowed for this NumberBox");



                //base.Text = value.ToString(this.Format);
                base.Text = value.ToString(GetFormat()).Replace(".", DecimalSymbol.ToString());
            }
        }

        /// <summary>
        /// Gets or sets the text content of the number box.
        /// </summary>
        override public string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                try
                {
                    this.Value = ParseStringToDouble(value);
                }
                catch (FormatException e)
                {
                    base.Text = value;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }


        /// <summary>
        ///	Add a JavaScript to the Page and call it from the onKeyPress event
        /// </summary>
        /// <param name="e"></param>
        override protected void OnPreRender(EventArgs e)
        {

            if (this.Page.Request.Browser.JavaScript == true)
            {
                // Build JavaScript		
                StringBuilder s = new StringBuilder();
                s.Append("\n<script type='text/javascript' language='JavaScript'>\n");
                s.Append("<!--\n");
                s.Append("    function NumberBoxKeyPress(event, dp, ml, dc, n) {\n");
                s.Append("var srcElement = event.srcElement ? event.srcElement : event.target;\n");
                //  old ..>s.Append("var myString = new String(window.event.srcElement.value);\n");
                s.Append("	     var myString = new String(srcElement.value);\n");
                s.Append("	     var pntPos = myString.indexOf(String.fromCharCode(dc));\n");
                s.Append("       np=ml-dp-1;\n");
                s.Append(" var obid = srcElement.id ;\n");
                //ff or other brow code
                s.Append("var keyChar = event.which;\n");

                //IE code
                s.Append("if (keyChar == null){\n");
                s.Append("keyChar = event.keyCode; }\n");

                
                s.Append("var r;\n");
                s.Append("var Curpos=-1;\n");
                //cursor position
                s.Append("Curpos = srcElement.selectionStart;\n");
                
                //IEcode start
                s.Append("if (Curpos!=-1){\n");
                s.Append("if( document.selection ) { \n");

                s.Append("	 r = document.selection.createRange();\n");

                s.Append("r.moveStart('character', -myString.length); \n");
                s.Append("Curpos =r.text.length;}}\n");


                                //if not numbers
                s.Append("       if ((keyChar < 48) || (keyChar > 57) ) {\n");

                s.Append("          if (keyChar == dc) {\n");

                s.Append("              if ((pntPos != -1) || (dp < 1)) {\n");
                s.Append("                  return false; \n");
                s.Append("              } }\n");

                //delete ,backspace and arrow keys for firefox
                s.Append("else \n");
                // s.Append("if ((keyChar == 8) || (keyChar == 0) || (keyChar == 37) || (keyChar == 38) ||(keyChar == 39) || (keyChar == 40 ) || (keyChar == 46))\n");
                s.Append("if ((keyChar == 8) || (keyChar == 0)){\n");

                s.Append("return true;\n}");
                s.Append("           else \n");
                s.Append("if (((keyChar == 45) && (!n || myString.length != 0)) || (keyChar != 45)) \n");
                s.Append("		     return false;\n");
                //	s.Append("       }\n");


                s.Append("       }\n");




                //if nos 
                s.Append(" else \n");

                s.Append(" { if ( myString.length > np-1 && pntPos ==-1 )  { \n");
                s.Append("   return false; } \n");




                s.Append(" else if (pntPos!=-1){\n");
                s.Append(" var dsubstring ; \n  ");
                s.Append(" var ssubstring ; \n  ");
                s.Append("ssubstring=myString.substring(0,pntPos); \n");
                s.Append("dsubstring=myString.substring(pntPos+1); \n");

                s.Append("if (dsubstring.length > dp-1 ){\n");
                s.Append(" if( Curpos > pntPos){  return false;} }   \n");

                s.Append("if (ssubstring.length > np-1) { \n");
                s.Append(" if(Curpos < np+1){ return false; }}\n");

                s.Append("}}\n");

                //s.Append("    }\n");

                s.Append("       return true;\n");
                s.Append("    }\n");
                s.Append("// -->\n");
                s.Append("</script>\n");

                // Add the Script to the Page
                this.Page.RegisterClientScriptBlock("NumberBoxKeyPress", s.ToString());

                // Add KeyPress Event
                try
                {
                    this.Attributes.Remove("onKeyPress");
                }
                finally
                {
                    this.Attributes.Add("onKeyPress", "return NumberBoxKeyPress(event, "
                                            + DecimalPlaces.ToString() + ", "
                                            + MaxLength.ToString() + ", "
                                            + ((int)DecimalSymbol).ToString() + ", "
                                            + AllowNegatives.ToString().ToLower() + ")");


                }
            }
        }

        /// <summary>
        /// Returns the RegularExpression string which can be used for validating 
        /// using a RegularExpressionValidator.
        /// </summary>
        virtual public string ValidationRegularExpression
        {
            get
            {
                StringBuilder regexp = new StringBuilder();

                
                int NumberPlaces1 = MaxLength - DecimalPlaces - 1;
                if (DecimalPlaces > 0)
                {

                    regexp.Append("^\\d{1,");
                    regexp.Append(NumberPlaces1);
                    regexp.Append("}(\\");
                    regexp.Append(DecimalSymbol);
                    regexp.Append("\\d{1,");
                    regexp.Append(DecimalPlaces.ToString());
                    regexp.Append("})?$");

                }
                else
                {
                    //regexp.Append("^\\d{1,4}$");
                    regexp.Append("^\\d{1,");
                    regexp.Append(NumberPlaces1);
                    regexp.Append("}$");
                }
                return regexp.ToString();
            }
    
        }

        /// <summary>
        /// Parse a String to a Double
        /// </summary>
        /// <param name="s">string to be parsed to a double</param>
        /// <returns>double value</returns>
        virtual protected double ParseStringToDouble(string s)
        {
            if (s == "")
            {

                s = "0";

            }

            s = s.Replace(DecimalSymbol.ToString(), ".");
            return double.Parse(s);
        }

        /// <summary>
        /// Returns the FormatString used to display the value in the number box
        /// </summary>
        /// <returns>Format string</returns>
        virtual protected string GetFormat()
        {
            StringBuilder f = new StringBuilder();
            f.Append("0");
            if (DecimalPlaces > 0)
            {
                f.Append(".");
                f.Append('0', DecimalPlaces);
            }

            return f.ToString();
        }

    }
}




In aspx page have added the control.


<rit:numberbox id="numOne" runat="server" DecimalSymbol="." MaxLength="8" Value="34" AutoPostBack="True" DecimalPlaces="3" CausesValidation="True" >34.00</rit:numberbox>


and in cs file have given in page load :
protected void Page_Load(object sender, System.EventArgs e)
		{
            numOne.DecimalPlaces = 4;
}



which is not been set. i.e the property value is not able to set dynamically .
i.e from cs file . it is taking the value set initially not overridded.


please help in this regard.

Thanks and Regards,
sriharsha
AnswerRe: how to set property for a user control from cs file Pin
Not Active2-Sep-09 2:33
mentorNot Active2-Sep-09 2:33 
AnswerRe: how to set property for a user control from cs file [modified] Pin
r a m e s h2-Sep-09 2:59
r a m e s h2-Sep-09 2:59 
GeneralRe: how to set property for a user control from cs file Pin
Abhijit Jana2-Sep-09 4:34
professionalAbhijit Jana2-Sep-09 4:34 
QuestionWant to Store database locally and then update it to remote server Pin
sjs4u2-Sep-09 1:16
sjs4u2-Sep-09 1:16 
AnswerRe: Want to Store database locally and then update it to remote server Pin
r a m e s h2-Sep-09 1:32
r a m e s h2-Sep-09 1:32 
GeneralRe: Want to Store database locally and then update it to remote server Pin
sjs4u2-Sep-09 1:36
sjs4u2-Sep-09 1:36 
GeneralRe: Want to Store database locally and then update it to remote server Pin
Christian Graus2-Sep-09 11:17
protectorChristian Graus2-Sep-09 11:17 
QuestionSetting focus with JavaScript Pin
dptalt2-Sep-09 1:09
dptalt2-Sep-09 1:09 
AnswerRe: Setting focus with JavaScript Pin
Jay Royall2-Sep-09 2:19
Jay Royall2-Sep-09 2:19 
GeneralRe: Setting focus with JavaScript Pin
dptalt2-Sep-09 4:47
dptalt2-Sep-09 4:47 
GeneralRe: Setting focus with JavaScript Pin
Abhijit Jana2-Sep-09 4:51
professionalAbhijit Jana2-Sep-09 4:51 
GeneralRe: Setting focus with JavaScript Pin
dptalt2-Sep-09 4:53
dptalt2-Sep-09 4:53 
AnswerRe: Setting focus with JavaScript Pin
Abhijit Jana2-Sep-09 4:35
professionalAbhijit Jana2-Sep-09 4:35 
GeneralRe: Setting focus with JavaScript Pin
Jay Royall2-Sep-09 4:42
Jay Royall2-Sep-09 4:42 
GeneralRe: Setting focus with JavaScript Pin
Abhijit Jana2-Sep-09 4:44
professionalAbhijit Jana2-Sep-09 4:44 
GeneralRe: Setting focus with JavaScript Pin
Jay Royall2-Sep-09 4:50
Jay Royall2-Sep-09 4:50 
GeneralRe: Setting focus with JavaScript Pin
Abhijit Jana2-Sep-09 4:52
professionalAbhijit Jana2-Sep-09 4:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.