|
Blikkies wrote: You also have to add premmisions to that folder where you store the file
Yes, This is only needed when you deploy the application on IIS Server. Its not mandatory for when we are doing it for Visual Studio.
Because, In Visual Studio, ASP.NET Engine having all kind of permssion to write on your harddrive. But, when you put the applicaiton on IIS, the application will run on Network Service Identity . Which having very minimum permission rights , and not to write on disk.
So we can have two solution,
a) Give the write access to all the user for that particular folder where we are uploding the file.
b) Make a different application pool with Identity of Local System ( which having write access permission) and assign it to the virtual directiry.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Use FileUpload Control
Try to uplaod file using,
If(FileUpload1.HasFile)
{
FileUpload1.SaveAs(path);
}
This code will work fine when you run your application from VS IDE . but when you deploy your code on IIS, you need to give the Access permission to the folder for user to upload file or you need to create a separate application pool for your site with Local System Identity .
Please let me know if you have any issue .
Thanks !
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
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
{
[
ToolboxData("<{0}:NumBox runat=server></{0}:NumBox>"),
DefaultProperty("DecimalPlaces")
]
public class NumBox : TextBox
{
private int mDecimalPlaces = 0;
private char mDecimalSymbol = '.';
private bool mAllowNegatives = true;
[
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; }
}
[
Bindable(true),
Category("Appearance"),
DefaultValue("."),
Description("The digit grouping symbol.")
]
public virtual char DecimalSymbol
{
get { return mDecimalSymbol; }
set { mDecimalSymbol = value; }
}
[
Bindable(true),
Category("Appearance"),
DefaultValue(true),
Description("True when negative values are allowed")
]
public virtual bool AllowNegatives
{
get { return mAllowNegatives; }
set { mAllowNegatives = value; }
}
[
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(GetFormat()).Replace(".", DecimalSymbol.ToString());
}
}
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;
}
}
}
override protected void OnPreRender(EventArgs e)
{
if (this.Page.Request.Browser.JavaScript == true)
{
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");
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");
s.Append("var keyChar = event.which;\n");
s.Append("if (keyChar == null){\n");
s.Append("keyChar = event.keyCode; }\n");
s.Append("var r;\n");
s.Append("var Curpos=-1;\n");
s.Append("Curpos = srcElement.selectionStart;\n");
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");
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");
s.Append("else \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(" 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(" return true;\n");
s.Append(" }\n");
s.Append("// -->\n");
s.Append("</script>\n");
this.Page.RegisterClientScriptBlock("NumberBoxKeyPress", s.ToString());
try
{
this.Attributes.Remove("onKeyPress");
}
finally
{
this.Attributes.Add("onKeyPress", "return NumberBoxKeyPress(event, "
+ DecimalPlaces.ToString() + ", "
+ MaxLength.ToString() + ", "
+ ((int)DecimalSymbol).ToString() + ", "
+ AllowNegatives.ToString().ToLower() + ")");
}
}
}
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,");
regexp.Append(NumberPlaces1);
regexp.Append("}$");
}
return regexp.ToString();
}
}
virtual protected double ParseStringToDouble(string s)
{
if (s == "")
{
s = "0";
}
s = s.Replace(DecimalSymbol.ToString(), ".");
return double.Parse(s);
}
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
|
|
|
|
|
We don't need to see all of your code, only the relevant bits. Most will just ignore a post with this much code.
only two letters away from being an asset
|
|
|
|
|
I think the value of the DecimalPlaces property is not stored in ViewState. You need to override LoadViewState and SaveViewState methods in the Custom Control.
modified on Wednesday, September 2, 2009 12:37 PM
|
|
|
|
|
I guess too.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hi,
I am having web application and windows application. Now I want to store all database tables information(server database) into the cache. I don't want any local database to store servers database. I want to use cache. Just like replica of the servers database These information can be access by windows application program. after updating cache information these information can be update to again web servers database.
How can I do? Is there any other solution so that I can use server database locally for some time , update some tables information to locally and the again update to servers database i.e. overwrite it to servers database only those which is updated locally.
Thanks
sjs4u
|
|
|
|
|
Do you want to cache information locally using your windows application or web application?
You cannot cache replica of server database tables locally using web appliction.
You can use SQL Server 2005 Express Edition if you want to do it using Windows application.
|
|
|
|
|
Thanks for the reply.
Well I am using windows application for getting cache data.
Update Cache data and then want to store that table on servers database which is updated locally.
Thanks
sjs4u
|
|
|
|
|
This question STILL has nothing to do with ASP.NET. You have a windows program, and I expect you will have a webservice which will upload it's data to a server. There's no ASP.NET involved here, even if there's an ASP.NET website on the other end of all this code.
I would just write a webservice which takes data and runs it into the database, I wouldn't be passing a whole database through the web, I'd just do an update as needed.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
With Javascript how do I set the focus to Text2 in ctl00_ContentPlaceHolder1_TimeEntryBox2_Panel1?
<div id="ctl00_ContentPlaceHolder1_TimeEntryBox1_Panel1" style="border-color:#7F9DB9;border-width:1px;border-style:Solid;width:89px;">
<input id="Text2" name="Text2" type="text" onkeyup="TimeEntryMinutesOnClick(this)" onblur="TimeEntryMinutesOnBlur(this)" style="border: 0px none #FFFFFF; width: 12px" maxlength="2" />
<input type="hidden" id="ctrlPrefix" name="ctrlPrefix" value='ctl00_ContentPlaceHolder1_TimeEntryBox1_'>
</div>
<div id="ctl00_ContentPlaceHolder1_TimeEntryBox2_Panel1" style="border-color:#7F9DB9;border-width:1px;border-style:Solid;width:89px;">
<input id="Text2" name="Text2" type="text" onkeyup="TimeEntryMinutesOnClick(this)" onblur="TimeEntryMinutesOnBlur(this)" style="border: 0px none #FFFFFF; width: 12px" maxlength="2" />
<input type="hidden" id="ctrlPrefix" name="ctrlPrefix" value='ctl00_ContentPlaceHolder1_TimeEntryBox2_'>
</div>
|
|
|
|
|
I am the voice of inexperience but I'm pretty sure it's bad practice to have more than 1 control on the page with the same ID. Can't you give each control a unique ID and use Javascript's .Focus method?
|
|
|
|
|
The HTML is coming from a User Control. Two of the same User Control are on the page. When viewing the source from the browser this is what it looks like.
|
|
|
|
|
If you have the source code you can chaneg the ID with meaning full name or use the ID that you are getting from ViewSource for focusing.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
|
Just find the ID of the control using GetElementByID method and use ControlObject.Focus() method to set the foucs.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
But he has 2 controls with the same ID. Will this approach still work?
|
|
|
|
|
Liqz wrote: But he has 2 controls with the same ID.
Why ? It should not be.
Or you can first run the application, from view Source what exact ID is generating for that page control then use Control.Focus(). This will work.
But this is not a good approch.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
In his markup he has 2 HTML input controls both with the ID of "Text2". I was under the impression that this was not good. If he calls 'Text2.Focus' from his Javascript, which input control will get the focus?
|
|
|
|
|
I guess it would the first one. but he need to find out the id using GetElementbyID, Text2.Focus(), will not work.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
When I use GetElementById("Text2") it always gets the one in within ctl00_ContentPlaceHolder1_TimeEntryBox1_Panel1. How do I get the one that is within ctl00_ContentPlaceHolder1_TimeEntryBox2_Panel1?
|
|
|
|
|
hi,
in my gridview i have some bound columns,and some template columns.and three columns dynamically added to the same gridview on the button click event.
code for dynamic created columns like this
For Each col As DataColumn In dtttt.Columns
For Each row As DataRow In dtt.Rows
If col.ColumnName = row.Item("CODE") Then
Dim customField1 As New TemplateField()
customField1.ShowHeader = True
customField1.HeaderTemplate = New Gridviewtemplate(DataControlRowType.Header, col.ColumnName, "", "label")
customField1.ItemTemplate = New Gridviewtemplate(DataControlRowType.DataRow, "", col.ColumnName, "Textbox")
DGV1.Columns.Add(customField1)
End If
Next
Next
DGV1.DataSource = dtttt
DGV1.DataBind()
but when the time of accessing the values of gridview except dynamically created template column values are not working
For i As Integer = 0 To DGV1.Rows.Count - 1
For count As Integer = 9 To DGV1.Columns.Count - 1
Try
dggrow = DGV1.Rows(i)
Select Case Incomes(Index)
Case 1
Earnings += CInt(dggrow.Cells(count).Text * Days)
Case 2
Earnings += CInt(dggrow.Cells(count).Text)
Case 3
Earnings -= CInt(dggrow.Cells(count).Text)
End Select
Catch ex As Exception
dggrow.Cells(count).Text = 0
End Try
Index += 1
Next
Next
dggrow.Cells(count).Text- here its not getting the value of dynamic created template column value.
how to access this value.anyone help me with this.this is very urgent.
|
|
|
|
|
Hi
As iam new to asp.net3.5 so i have some basic doubt please clarify my doubt with some example if possible,my question is WHAT IS THE USE OF DATA SOURCE,DATA BIND(),FILL(),DTATSET,DATAADPTER IN datagridview and how to use it.
|
|
|
|
|
Here's some advice.
1 - buy a book and read it
2 - learn to use google, especially when you have no idea what you're doing, because your questions right now are so basic and lacking in any sort of understanding, that you need to read articles, not forum replies
3 - before you post in a forum, read the guidelines.
your question tells me that you really have no idea about anything you're looking at. I'd assume that you're teaching yourself to be this lacking in resources, but experience tells me that the odds are good that someone is actually paying you to not know anything about ASP.NET. I hope that is not true. Either way, if you don't have a teacher, you need to buy a good book and work through it. I don't know if you know anything about programming, if you do not know C# or VB.NET, you should learn that first, because ASP.NET is a framework on top of .NET, and you should not learn both at the same time. Plenty of people try to do that, they end up asking clueless questions for hapless and eventually furious clients, whose projects never quite work, and are poorly written and unmaintainable.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
If you google it, you'll get many good articles about all these stuff.
|
|
|
|