|
Define the ID of file control as FileUpload then add a Button named as btnSubmit adn write the folowing code on the Button's onclick event
private void btnSubmit_Click(object sender, System.EventArgs e)
{
try
{
if (isVaildData())
{
if (FileUpload!=null)
{
string DestinationPath = Server.MapPath("../UpLoadFile/Images").ToString() ;
string ImgName =GetUniqueId()+ System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);
ImgName = ImgName.Replace(" ", "");
string saveLoaction=DestinationPath+"\\"+ImgName;
FileUpload.PostedFile.SaveAs(saveLoaction);
Session["SavedFile"]=ImgName;
btnSubmit.Enabled=false;
btnRemoveFile.Enabled=true;
lblMessage.Text="File :" + ImgName + " Uploaded Successfully ";
lblMessage1.Text=ImgName;
Session["strFileType"]=Request.QueryString["Type"].ToString().Trim();
}
else
lblMessage.Text="Please Browse a File.";
}
}
catch(Exception ex)
{
string str=ex.Message;
}
}
rivate Boolean isVaildData()
{
if (FileUpload.PostedFile.ContentLength==0)
{
lblMessage.Text="Please Select an valid file";
return false;
}
if ( FileUpload.PostedFile.FileName!="" )
{
string filename=System.IO.Path.GetFileName(FileUpload.PostedFile.FileName.ToString());
string extension = System.IO.Path.GetExtension(FileUpload.PostedFile.FileName);
string Type = Request.QueryString["Type"].ToString();
switch(extension.ToLower())
{
case ".pdf":
break;
case ".doc":
break;
case ".jpg":
break;
case ".gif":
break;
default:
{
lblMessage.Text="Invalid Disclosures file :-" + FileUpload.PostedFile.FileName;
return false;
}
}
}
return true;
}
Neeraj
|
|
|
|
|
Hi Neeraj
thanks a lot for your vital support.
can you post a vb.net version of the code as i am using vb.net as my code behind..
thanks again
pradip kishore
|
|
|
|
|
Hi Neeraj
another small task for you
suppose i uploaded a file and i want to give a link of it for the user on a page.so how the user link can be automatically created on a user interface when i will upload a page..?
pradip kishore
|
|
|
|
|
i have a webform in which there are several textbox controls. i want that when i press the reset button all the textbox controls should be cleared..how can i do ths by looping through the textbox controls.. i am using vb.net as code behind
its urgent
thanks in advance
pradip kishore
|
|
|
|
|
You mean a reset button?
<input type="reset" value="Reset" />
|
|
|
|
|
Is it possible to make some of the DataGrid functionality to client-side? Such as the Edit, Update, Cancel, Delete functionality? Everytime I click on a row's Edit button, I wait 2 seconds before I see the Edit controls (eg. textboxes, drop-down combos, checkboxes). I understand that the DataGrid's Edit, Cancel, Update, Delete functions are server-side because it uses ASP.NET postback handler functions.
What I like is these Edit, Cancel, Update, Delete functions being on client-side, but uses AJAX requests in background. This would make the user feel fluid editing (opposed to the 2 seconds delay for each DataGrid button pressed).
Is this possible with the standard DataGrid? Or can the DataGrid be overrided so that the Edit, Cancel, Update, Delete functions operate on client-side, and sends the actual Update/Delete command using AJAX? This is so much faster and better than the current slow DataGrid.
If one has to code all this functionality manually, how would one go about it?
If I don't see much prospect of the DataGrid, I'll eventually abandon ASP.NET with GWT.
|
|
|
|
|
|
I am developing a contractors database system and the specs is that I must program in tiers. So how does this thing work because i am still learning
Karabo
|
|
|
|
|
wrote: I am developing a contractors database system and the specs is that I must program in tiers. So how does this thing work because i am still learning
You separate out the presentation, the business logic and the database access into separate assemblies (actually, you don't have to put them in different assemblies, but it helps you enforce the separation of tiers). The presentation layer can only talk to the business logic and the business logic can only talk to the database.
Various design patterns can help you achieve this. So, you might start by looking for books on design patterns. If you've never done any before then Head First Design Patterns is an excellent book - the code samples are in Java, but should be easy enough for anyone to understand.
|
|
|
|
|
|
Hi All
I am working with SQL Datasource thru program logic. I am fine till the time my stored procedure returns single result set. I can read the dataview and the return values also.
But how i can read values, if my SP return multiple result set? For exmaple
Select Name from table
Select webage from Table1
Any help,
Amit Gugnani
|
|
|
|
|
if you are using DataReader for getting resultsets then use DataReader's NextResultSet() method to move the next resultset
if you are using DataSet for getting resultsets then the resultsets available in the form of DataSet.Tables[0],DataSet.Tables[1],..DataSet.Tables[n], I mean Table Collection object
Regards,
Sylvester G
Senior Software Engineer
Xoriant Solutions
|
|
|
|
|
Is it better to use SqlDataSource in 2.0 ? Wht is ur view....
Because the power of sqldatasource is very impressive. I don't need to write any data datareader code, it can return dataset/data reader in form of dataview....
I am confuse, should i use this or not in my DAL layer. pl share your experience...
Thx
Amit
Thx
|
|
|
|
|
Yaa of cource you can use the SqlDataSource 2.0. New development is for more userfriendliness. And in the SqlDataSource 2.0 we have to do little to work. You should't use the SqlDataReader in any simple condition.
naresh patel
|
|
|
|
|
Thanks Naresh...Could you help me with the below query also..
Hi All
I am working with SQL Datasource thru program logic. I am fine till the time my stored procedure returns single result set. I can read the dataview and the return values also.
But how i can read values, if my SP return multiple result set? For exmaple
Select Name from table
Select webage from Table1
Any help,
Amit
|
|
|
|
|
I'm sorry in advance because I'm very new to this. I think I've done a decent job doing my homework first though. I've searched what seems like everywhere for an answer before posting here but I've found nothing that does exactly what I'm hoping for.
Using developer 2005 with C# as my primary language.
What I want to do is be able to execute code when the user closes the web page very similar to a FormClosing event in a windows application. Is this not possible?
Two things I've sort of ruled out are:
Using Global.asax and session_end doesn't seem to work because I don't think I'll have access to my other methods that way(session_end seems sort of iffy anyway from what I've read).
Form_Unload fires everytime the user switches between pages(which I don't want)
Any advice appreciated.
|
|
|
|
|
No, it's not possible. The web is disconnected, what someone does on the browser, you have no idea. I think you can set something up in javascript, but I don't think it's reliable.
your C# code has nothing to do with the users actions, except when the user does something that creates a postback or a page request. Closing the browser does neither.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
You can use onunload event handler of <body> object, and send some specific request to server in it - it can be implemented as synchronous XMLHTTP request.
I have seen several applications which performs logout procedure in this way.
|
|
|
|
|
Hi everybody, it's me again(SPIKE). Did anyone of you know how to keep the dropdownlist control behind a pop up menu? I just downloaded the control from this Site and I can't seem to fix it; and, if it's not too much trouble, could you help me adding buttons to the pop up menu to use it like a MSGBOX(I'm talking about yes-no questions).
You can send your answers to spikereloaded@gmail.com. PLEASE HELP ME.
Spike reloaded
|
|
|
|
|
Hi, Spike. I suspect you read SOME of my earlier reply, as your subject/header is at least sensible now. Just to remind you of my other points:
1 - if you have a question about an article, you should ask it to the article auther ( that is, in the forum for the article ). This site has lots of articles, from lots of people. Not all of them necessarily still read the site, or read it often enough to see this. They will get an email if you ask in the right place.
2 - This is a limitation of many javascript driven menus, you may just need to find one that doesn't do that.
Thanks for playing.
James_Marsters wrote: You can send your answers to spikereloaded@gmail.com.
No-one will do that. For starters, it gives you someone's email address, when perhaps they don't want to offer it. Secondly, why would we want to go out of our way to help someone who seems to be saying they aren't going to come back to check the site ?
In any case, if you gave this email in your profile, you'll get an email from any answers, as you'd have found when I replied to you on the site last time.
It's also not good to put your email address like that. CP will never spam you, but the site can't stop bots from searching the text in the forums for email addresses, for spam lists.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hey:
I am facing problem in my asp.net/vb.net 2.0 program. i want to Select,Add, Delete,Edit,Update,Cancel. Ineteresting thing is that Event is working except Update,Delete Gridview Without inserted data into database.
my requirement is to add multiple Items in gridview and after successful data entry and in last, i want to save gridview all rows at once, not one by
one.
i place two/three textboxes followed by add button which will add textbox values in to gridview (Note: Not in Database), if due to any entry error, i simply want to edit,update/delete inserted rows from the gridview.
Note: Gridview EditColumns , i add two boundfields and then converted to Templatefiled and i have unchecked auto generate fields becoz i dont wana any extra fields. finally when i press Post button it will post all gridview data rows once and Problem is update/delete datagrid before post the data into the database, may be update/delete i will add more values in gridview and then post. i think enough description to tell someone wat i actually wants. in advance thankyou to help me out.
Note: just right the code on request area and reply me back. once again thank you. remember i am new to asp.net and vb.net and please do it only in asp/vb.net
i am pasting my code below, please help me out how i can do this on fly,please dont forget to lable the code.
Here is my Code
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports System.Configuration
Imports System.Collections
Partial Class _Default
Inherits System.Web.UI.Page
Dim dt As Data.DataTable
Dim ds As New Data.DataSet
Dim ds1 As New Data.DataSet
Dim dr As Data.DataRow
Dim dc As New Data.DataColumn
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SqlCon As New SqlConnection
Dim SqlCom As SqlCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SqlCon.ConnectionString = System.Configuration.ConfigurationManager.AppSettings.Get("alisons")
'SqlConnection("Data Source=dell;Initial Catalog=alisons;Integrated Security=True")
'cn.Open("Dsn=alisons; uid=alisons; pwd=alisons;")
dt = New Data.DataTable
ds = New Data.DataSet
If Not IsPostBack Then
Session("ds") = ds
ds.Tables.Add(dt)
ds.Tables(0).Columns.Add(New Data.DataColumn("Code"))
ds.Tables(0).Columns.Add(New Data.DataColumn("Name"))
ds.AcceptChanges()
End If
End Sub
Sub fillGrid()
ds1 = CType(Session("ds"), Data.DataSet)
GridView1.DataSource = ds1.Tables(0)
GridView1.DataBind()
End Sub
Protected Sub cmdAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
ds1 = CType(Session("ds"), Data.DataSet)
dr = ds1.Tables(0).NewRow()
dr("Code") = Txt_Code.Text
dr("Name") = txt_Name.Text
ds1.Tables(0).Rows.Add(dr)
ds1.AcceptChanges()
fillGrid()
Txt_Code.Text = ""
txt_Name.Text = ""
End Sub
Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PageIndexChanged
fillGrid()
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
End Sub
Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
GridView1.EditIndex = -1
fillGrid()
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
' delete row
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.EditIndex = e.NewEditIndex
fillGrid()
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
' Facing Problem Here
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
' Facing Problem Here
'ds1 = CType(Session("ds"), Data.DataSet)
Dim GRow0 As GridViewRow = GridView1.Rows(e.RowIndex)
Dim GRow1 As GridViewRow = GridView1.Rows(e.RowIndex)
If Not GRow0 Is Nothing And Not GRow1 Is Nothing Then
Dim t0 As TextBox = GRow0.FindControl("texcol0")
Dim t1 As TextBox = GRow1.FindControl("texcol1")
'T = GRow.FindControl("Code")
If Not t0 Is Nothing And Not t1 Is Nothing Then
Response.Write("The Col0 is Entered " + t0.Text)
Response.Write("The Col1 is Entered " + t1.Text)
'dr = ds1.Tables(0).NewRow()
'dr("Code") = t0.Text
'dr("Name") = t1.Text
'ds1.Tables(0).Rows.Add(dr)
ds1.AcceptChanges()
'fillGrid()
End If
End If
End Sub
Protected Sub btnPost_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPost.Click
'Dim ds1 As DataSet = CType(Session("ds"), DataSet)
'Dim datasource1 As SqlDataSource = New SqlDataSource()
Dim paramCode As String
Dim paramName As String
Dim sqlstr As String
Dim dr As DataRow
Dim datasource1 As SqlDataSource
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
datasource1 = New SqlDataSource()
ds1 = CType(Session("ds"), Data.DataSet)
cn.Open("DSN=alisons; uid=alisons; pwd=alisons;")
Response.Write(cn)
If cn.State = 1 Then
'cn.BeginTrans()
For Each dr In ds1.Tables(0).Rows
paramCode = Trim(dr("Code"))
paramName = Trim(dr("Name"))
sqlstr = "INSERT INTO Tbl_LOV(Code, Name) VALUES ('" + paramCode + "','" + paramName + "')"
cn.Execute(sqlstr)
Next
'cn.CommitTrans()
Response.Write("Inserted")
End If
End Sub
Protected Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
GridView1.EditIndex = -1
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
End Sub
End Class
-----------------------------------------------------------------------------
Regards,
Ricky.
|
|
|
|
|
Hi All...
I have a login page(page1) that checks the user name and his password for a user, when the authorized user goes into the next page(page2)-I initialize an (ID session) and then when he loggs off I empty the session...
but, by the back button he could return back again to the 2nd page (and this is the problem )...
Could you help me..
Thanks alot...
Nour
|
|
|
|
|
All your pages should check if the user is logged in, and if not, deny access.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I did that...
But what I need is not to allow the user to go back when back button is pressed...
Thanks
|
|
|
|
|
Well, to do that, you simply need to not serve the page if the security check fails. If they are not logged in, your base page should redirect to the login page.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|