Thursday, March 29, 2012
object persistence
the page reloads after Post Back, I get an error saying the object
does not exist. What do I need too do to make object persistant on
server?
Help appreciated.Try putting the object into Session State or ViewState.
Sesssion("MyObject") = oMyObject
Then on postback:
oMyObject = CType(Session("MyObject"),cMyObject)
--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
Developer for Hire
"Atif Jalal" <matif@.hotmail.com> wrote in message
news:b7af12d4.0308120905.51c736bd@.posting.google.c om...
> I instatiate an object first time when an asp.net page loads. But when
> the page reloads after Post Back, I get an error saying the object
> does not exist. What do I need too do to make object persistant on
> server?
> Help appreciated.
Every time the Page reloads, all objects in it must be rebuilt from scratch.
Either, as Steve suggested, persist the object in some caching mechanism, or
re-create the object with each PostBack.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.
"Atif Jalal" <matif@.hotmail.com> wrote in message
news:b7af12d4.0308120905.51c736bd@.posting.google.c om...
> I instatiate an object first time when an asp.net page loads. But when
> the page reloads after Post Back, I get an error saying the object
> does not exist. What do I need too do to make object persistant on
> server?
> Help appreciated.
Monday, March 26, 2012
object reference not set to an instance of an object
I'm getting this error saying that Server Error 'in
'/mcsdWebApps/Chapter5/DBruntime' Application.
Object reference not set to an instance of an object. It says the error is
on line 39 which is
Dim rowInsert As DataRow = dsContacts.Tables("Contacts").NewRow
Thanks in advance for any help!
Here is the full code:
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e as System.EventArgs) Handles MyBase.Load
'1. Create the data connection.
Dim ContactMgmt As New SqlConnection _
(" Server=(local);database=Contacts;Trusted
_Connection=yes")
'Create an adapter.
Dim adptContactMgmt As New _
SqlDataAdapter("select * from Contacts", ContactMgmt)
'2. Create a data set.
Dim dsContacts As New DataSet()
'Set select command.
adptContactMgmt.SelectCommand.CommandText = _
"SELECT * FROM Contacts"
'3. Create, insert, delete, and update commands automatically.
Dim cmdContactMgmt As SqlCommandBuilder = New _
SqlCommandBuilder(adptContactMgmt)
'4. Create a new row.
'HERE'S WHERE I'M GETTING THE ERROR!
Dim rowInsert as DataRow = dsContacts.Tables("Contacts").NewRow
'Add data to fields in the row.
rowInsert("ContactId") = 3
rowInsert("FirstName") = "Mary"
rowInsert("LastName") = "Smith"
rowInsert("WorkPhone") = "(444) 222-2222"
'Add the row to the data set.
dsContacts.Tables("Contacts").Rows.Add(rowInsert)
'5. Update the database.
adptContactMgmt.Update(dsContacts.Tables("Contacts"))
End SubHi,
The problem is that you have not filled your dataset so the dataset does not
have a table called Contacts.
Here is a modified version of the code that should get you going.
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e as System.EventArgs) Handles MyBase.Load
'1. Create the data connection.
Dim ContactMgmt As New SqlConnection _
(" Server=(local);database=Contacts;Trusted
_Connection=yes")
'Create an adapter.
Dim adptContactMgmt As New _
SqlDataAdapter("select * from Contacts", ContactMgmt)
'2. Create a data set.
Dim dsContacts As New DataSet()
'Set select command. This is not needed since this was set when you
constructed the SqlDataAdapter
'3. Create, insert, delete, and update commands automatically.
Dim cmdContactMgmt As SqlCommandBuilder = New _
SqlCommandBuilder(adptContactMgmt)
'*** The missing part, Fill the dataset using the DataAdapter and pass the
table name that you want
' the DataAdapter to use.
adptContactMgmt.Fill(dsContacts, "Contacts")
'4. Create a new row.
Dim rowInsert as DataRow = dsContacts.Tables("Contacts").NewRow
'Add data to fields in the row.
rowInsert("ContactId") = 3
rowInsert("FirstName") = "Mary"
rowInsert("LastName") = "Smith"
rowInsert("WorkPhone") = "(444) 222-2222"
'Add the row to the data set.
dsContacts.Tables("Contacts").Rows.Add(rowInsert)
'5. Update the database.
adptContactMgmt.Update(dsContacts.Tables("Contacts"))
End Sub
Hope this helps
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"student" <mr_chat123@.yahoo.com> wrote in message
news:24HBd.9293$by5.9098@.newssvr19.news.prodigy.com...
> Hello all, I have this problem in this code I am studying.
> I'm getting this error saying that Server Error 'in
> '/mcsdWebApps/Chapter5/DBruntime' Application.
> Object reference not set to an instance of an object. It says the error is
> on line 39 which is
> Dim rowInsert As DataRow = dsContacts.Tables("Contacts").NewRow
> Thanks in advance for any help!
> Here is the full code:
> Private Sub Page_Load(ByVal sender As System.Object, _
> ByVal e as System.EventArgs) Handles MyBase.Load
> '1. Create the data connection.
> Dim ContactMgmt As New SqlConnection _
> (" Server=(local);database=Contacts;Trusted
_Connection=yes")
> 'Create an adapter.
> Dim adptContactMgmt As New _
> SqlDataAdapter("select * from Contacts", ContactMgmt)
> '2. Create a data set.
> Dim dsContacts As New DataSet()
> 'Set select command.
> adptContactMgmt.SelectCommand.CommandText = _
> "SELECT * FROM Contacts"
> '3. Create, insert, delete, and update commands automatically.
> Dim cmdContactMgmt As SqlCommandBuilder = New _
> SqlCommandBuilder(adptContactMgmt)
> '4. Create a new row.
> 'HERE'S WHERE I'M GETTING THE ERROR!
> Dim rowInsert as DataRow = dsContacts.Tables("Contacts").NewRow
> 'Add data to fields in the row.
> rowInsert("ContactId") = 3
> rowInsert("FirstName") = "Mary"
> rowInsert("LastName") = "Smith"
> rowInsert("WorkPhone") = "(444) 222-2222"
> 'Add the row to the data set.
> dsContacts.Tables("Contacts").Rows.Add(rowInsert)
> '5. Update the database.
> adptContactMgmt.Update(dsContacts.Tables("Contacts"))
> End Sub
>
Thanks for the help that got rid of the error, only now I'm getting a blank
screen when I view the code in a browser Internet Explorer, any idea as to
what is causing this'
thanks,
student
"Chris Taylor" <chris_taylor_za@.hotmail.com> wrote in message
news:%23TeGJtG8EHA.2700@.TK2MSFTNGP14.phx.gbl...
> Hi,
> The problem is that you have not filled your dataset so the dataset does
not
> have a table called Contacts.
> Here is a modified version of the code that should get you going.
> Private Sub Page_Load(ByVal sender As System.Object, _
> ByVal e as System.EventArgs) Handles MyBase.Load
> '1. Create the data connection.
> Dim ContactMgmt As New SqlConnection _
> (" Server=(local);database=Contacts;Trusted
_Connection=yes")
> 'Create an adapter.
> Dim adptContactMgmt As New _
> SqlDataAdapter("select * from Contacts", ContactMgmt)
> '2. Create a data set.
> Dim dsContacts As New DataSet()
> 'Set select command. This is not needed since this was set when you
> constructed the SqlDataAdapter
> '3. Create, insert, delete, and update commands automatically.
> Dim cmdContactMgmt As SqlCommandBuilder = New _
> SqlCommandBuilder(adptContactMgmt)
> '*** The missing part, Fill the dataset using the DataAdapter and pass
the
> table name that you want
> ' the DataAdapter to use.
> adptContactMgmt.Fill(dsContacts, "Contacts")
> '4. Create a new row.
> Dim rowInsert as DataRow = dsContacts.Tables("Contacts").NewRow
> 'Add data to fields in the row.
> rowInsert("ContactId") = 3
> rowInsert("FirstName") = "Mary"
> rowInsert("LastName") = "Smith"
> rowInsert("WorkPhone") = "(444) 222-2222"
> 'Add the row to the data set.
> dsContacts.Tables("Contacts").Rows.Add(rowInsert)
> '5. Update the database.
> adptContactMgmt.Update(dsContacts.Tables("Contacts"))
> End Sub
>
> Hope this helps
> --
> Chris Taylor
> http://dotnetjunkies.com/weblog/chris.taylor
> "student" <mr_chat123@.yahoo.com> wrote in message
> news:24HBd.9293$by5.9098@.newssvr19.news.prodigy.com...
is
>
Hi,
I do not see what data control you are using, but one thing with ASP.NET is
that once you have setup the databinding you have to call DataBind()
otherwise no binding happens.
Hope this helps
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"student" <mr_chat123@.yahoo.com> wrote in message
news:ZQ_Bd.9661$by5.495@.newssvr19.news.prodigy.com...
> Thanks for the help that got rid of the error, only now I'm getting a
blank
> screen when I view the code in a browser Internet Explorer, any idea as to
> what is causing this'
> thanks,
> student
> "Chris Taylor" <chris_taylor_za@.hotmail.com> wrote in message
> news:%23TeGJtG8EHA.2700@.TK2MSFTNGP14.phx.gbl...
> not
> the
error
> is
>
Saturday, March 24, 2012
object reference not set to an instance of an object
I'm getting this error saying that Server Error 'in
'/mcsdWebApps/Chapter5/DBruntime' Application.
Object reference not set to an instance of an object. It says the error is
on line 39 which is
Dim rowInsert As DataRow = dsContacts.Tables("Contacts").NewRow
Thanks in advance for any help!
Here is the full code:
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e as System.EventArgs) Handles MyBase.Load
'1. Create the data connection.
Dim ContactMgmt As New SqlConnection _
("Server=(local);database=Contacts;Trusted_Connectio n=yes")
'Create an adapter.
Dim adptContactMgmt As New _
SqlDataAdapter("select * from Contacts", ContactMgmt)
'2. Create a data set.
Dim dsContacts As New DataSet()
'Set select command.
adptContactMgmt.SelectCommand.CommandText = _
"SELECT * FROM Contacts"
'3. Create, insert, delete, and update commands automatically.
Dim cmdContactMgmt As SqlCommandBuilder = New _
SqlCommandBuilder(adptContactMgmt)
'4. Create a new row.
'HERE'S WHERE I'M GETTING THE ERROR!
Dim rowInsert as DataRow = dsContacts.Tables("Contacts").NewRow
'Add data to fields in the row.
rowInsert("ContactId") = 3
rowInsert("FirstName") = "Mary"
rowInsert("LastName") = "Smith"
rowInsert("WorkPhone") = "(444) 222-2222"
'Add the row to the data set.
dsContacts.Tables("Contacts").Rows.Add(rowInsert)
'5. Update the database.
adptContactMgmt.Update(dsContacts.Tables("Contacts"))
End SubHi,
The problem is that you have not filled your dataset so the dataset does not
have a table called Contacts.
Here is a modified version of the code that should get you going.
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e as System.EventArgs) Handles MyBase.Load
'1. Create the data connection.
Dim ContactMgmt As New SqlConnection _
("Server=(local);database=Contacts;Trusted_Connectio n=yes")
'Create an adapter.
Dim adptContactMgmt As New _
SqlDataAdapter("select * from Contacts", ContactMgmt)
'2. Create a data set.
Dim dsContacts As New DataSet()
'Set select command. This is not needed since this was set when you
constructed the SqlDataAdapter
'3. Create, insert, delete, and update commands automatically.
Dim cmdContactMgmt As SqlCommandBuilder = New _
SqlCommandBuilder(adptContactMgmt)
'*** The missing part, Fill the dataset using the DataAdapter and pass the
table name that you want
' the DataAdapter to use.
adptContactMgmt.Fill(dsContacts, "Contacts")
'4. Create a new row.
Dim rowInsert as DataRow = dsContacts.Tables("Contacts").NewRow
'Add data to fields in the row.
rowInsert("ContactId") = 3
rowInsert("FirstName") = "Mary"
rowInsert("LastName") = "Smith"
rowInsert("WorkPhone") = "(444) 222-2222"
'Add the row to the data set.
dsContacts.Tables("Contacts").Rows.Add(rowInsert)
'5. Update the database.
adptContactMgmt.Update(dsContacts.Tables("Contacts"))
End Sub
Hope this helps
--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"student" <mr_chat123@.yahoo.com> wrote in message
news:24HBd.9293$by5.9098@.newssvr19.news.prodigy.co m...
> Hello all, I have this problem in this code I am studying.
> I'm getting this error saying that Server Error 'in
> '/mcsdWebApps/Chapter5/DBruntime' Application.
> Object reference not set to an instance of an object. It says the error is
> on line 39 which is
> Dim rowInsert As DataRow = dsContacts.Tables("Contacts").NewRow
> Thanks in advance for any help!
> Here is the full code:
> Private Sub Page_Load(ByVal sender As System.Object, _
> ByVal e as System.EventArgs) Handles MyBase.Load
> '1. Create the data connection.
> Dim ContactMgmt As New SqlConnection _
> ("Server=(local);database=Contacts;Trusted_Connectio n=yes")
> 'Create an adapter.
> Dim adptContactMgmt As New _
> SqlDataAdapter("select * from Contacts", ContactMgmt)
> '2. Create a data set.
> Dim dsContacts As New DataSet()
> 'Set select command.
> adptContactMgmt.SelectCommand.CommandText = _
> "SELECT * FROM Contacts"
> '3. Create, insert, delete, and update commands automatically.
> Dim cmdContactMgmt As SqlCommandBuilder = New _
> SqlCommandBuilder(adptContactMgmt)
> '4. Create a new row.
> 'HERE'S WHERE I'M GETTING THE ERROR!
> Dim rowInsert as DataRow = dsContacts.Tables("Contacts").NewRow
> 'Add data to fields in the row.
> rowInsert("ContactId") = 3
> rowInsert("FirstName") = "Mary"
> rowInsert("LastName") = "Smith"
> rowInsert("WorkPhone") = "(444) 222-2222"
> 'Add the row to the data set.
> dsContacts.Tables("Contacts").Rows.Add(rowInsert)
> '5. Update the database.
> adptContactMgmt.Update(dsContacts.Tables("Contacts"))
> End Sub
Thanks for the help that got rid of the error, only now I'm getting a blank
screen when I view the code in a browser Internet Explorer, any idea as to
what is causing this??
thanks,
student
"Chris Taylor" <chris_taylor_za@.hotmail.com> wrote in message
news:%23TeGJtG8EHA.2700@.TK2MSFTNGP14.phx.gbl...
> Hi,
> The problem is that you have not filled your dataset so the dataset does
not
> have a table called Contacts.
> Here is a modified version of the code that should get you going.
> Private Sub Page_Load(ByVal sender As System.Object, _
> ByVal e as System.EventArgs) Handles MyBase.Load
> '1. Create the data connection.
> Dim ContactMgmt As New SqlConnection _
> ("Server=(local);database=Contacts;Trusted_Connectio n=yes")
> 'Create an adapter.
> Dim adptContactMgmt As New _
> SqlDataAdapter("select * from Contacts", ContactMgmt)
> '2. Create a data set.
> Dim dsContacts As New DataSet()
> 'Set select command. This is not needed since this was set when you
> constructed the SqlDataAdapter
> '3. Create, insert, delete, and update commands automatically.
> Dim cmdContactMgmt As SqlCommandBuilder = New _
> SqlCommandBuilder(adptContactMgmt)
> '*** The missing part, Fill the dataset using the DataAdapter and pass
the
> table name that you want
> ' the DataAdapter to use.
> adptContactMgmt.Fill(dsContacts, "Contacts")
> '4. Create a new row.
> Dim rowInsert as DataRow = dsContacts.Tables("Contacts").NewRow
> 'Add data to fields in the row.
> rowInsert("ContactId") = 3
> rowInsert("FirstName") = "Mary"
> rowInsert("LastName") = "Smith"
> rowInsert("WorkPhone") = "(444) 222-2222"
> 'Add the row to the data set.
> dsContacts.Tables("Contacts").Rows.Add(rowInsert)
> '5. Update the database.
> adptContactMgmt.Update(dsContacts.Tables("Contacts"))
> End Sub
>
> Hope this helps
> --
> Chris Taylor
> http://dotnetjunkies.com/weblog/chris.taylor
> "student" <mr_chat123@.yahoo.com> wrote in message
> news:24HBd.9293$by5.9098@.newssvr19.news.prodigy.co m...
> > Hello all, I have this problem in this code I am studying.
> > I'm getting this error saying that Server Error 'in
> > '/mcsdWebApps/Chapter5/DBruntime' Application.
> > Object reference not set to an instance of an object. It says the error
is
> > on line 39 which is
> > Dim rowInsert As DataRow = dsContacts.Tables("Contacts").NewRow
> > Thanks in advance for any help!
> > Here is the full code:
> > Private Sub Page_Load(ByVal sender As System.Object, _
> > ByVal e as System.EventArgs) Handles MyBase.Load
> > '1. Create the data connection.
> > Dim ContactMgmt As New SqlConnection _
> > ("Server=(local);database=Contacts;Trusted_Connectio n=yes")
> > 'Create an adapter.
> > Dim adptContactMgmt As New _
> > SqlDataAdapter("select * from Contacts", ContactMgmt)
> > '2. Create a data set.
> > Dim dsContacts As New DataSet()
> > 'Set select command.
> > adptContactMgmt.SelectCommand.CommandText = _
> > "SELECT * FROM Contacts"
> > '3. Create, insert, delete, and update commands automatically.
> > Dim cmdContactMgmt As SqlCommandBuilder = New _
> > SqlCommandBuilder(adptContactMgmt)
> > '4. Create a new row.
> > 'HERE'S WHERE I'M GETTING THE ERROR!
> > Dim rowInsert as DataRow = dsContacts.Tables("Contacts").NewRow
> > 'Add data to fields in the row.
> > rowInsert("ContactId") = 3
> > rowInsert("FirstName") = "Mary"
> > rowInsert("LastName") = "Smith"
> > rowInsert("WorkPhone") = "(444) 222-2222"
> > 'Add the row to the data set.
> > dsContacts.Tables("Contacts").Rows.Add(rowInsert)
> > '5. Update the database.
> > adptContactMgmt.Update(dsContacts.Tables("Contacts"))
> > End Sub
Hi,
I do not see what data control you are using, but one thing with ASP.NET is
that once you have setup the databinding you have to call DataBind()
otherwise no binding happens.
Hope this helps
--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"student" <mr_chat123@.yahoo.com> wrote in message
news:ZQ_Bd.9661$by5.495@.newssvr19.news.prodigy.com ...
> Thanks for the help that got rid of the error, only now I'm getting a
blank
> screen when I view the code in a browser Internet Explorer, any idea as to
> what is causing this??
> thanks,
> student
> "Chris Taylor" <chris_taylor_za@.hotmail.com> wrote in message
> news:%23TeGJtG8EHA.2700@.TK2MSFTNGP14.phx.gbl...
> > Hi,
> > The problem is that you have not filled your dataset so the dataset does
> not
> > have a table called Contacts.
> > Here is a modified version of the code that should get you going.
> > Private Sub Page_Load(ByVal sender As System.Object, _
> > ByVal e as System.EventArgs) Handles MyBase.Load
> > '1. Create the data connection.
> > Dim ContactMgmt As New SqlConnection _
> > ("Server=(local);database=Contacts;Trusted_Connectio n=yes")
> > 'Create an adapter.
> > Dim adptContactMgmt As New _
> > SqlDataAdapter("select * from Contacts", ContactMgmt)
> > '2. Create a data set.
> > Dim dsContacts As New DataSet()
> > 'Set select command. This is not needed since this was set when you
> > constructed the SqlDataAdapter
> > '3. Create, insert, delete, and update commands automatically.
> > Dim cmdContactMgmt As SqlCommandBuilder = New _
> > SqlCommandBuilder(adptContactMgmt)
> > '*** The missing part, Fill the dataset using the DataAdapter and pass
> the
> > table name that you want
> > ' the DataAdapter to use.
> > adptContactMgmt.Fill(dsContacts, "Contacts")
> > '4. Create a new row.
> > Dim rowInsert as DataRow = dsContacts.Tables("Contacts").NewRow
> > 'Add data to fields in the row.
> > rowInsert("ContactId") = 3
> > rowInsert("FirstName") = "Mary"
> > rowInsert("LastName") = "Smith"
> > rowInsert("WorkPhone") = "(444) 222-2222"
> > 'Add the row to the data set.
> > dsContacts.Tables("Contacts").Rows.Add(rowInsert)
> > '5. Update the database.
> > adptContactMgmt.Update(dsContacts.Tables("Contacts"))
> > End Sub
> > Hope this helps
> > --
> > Chris Taylor
> > http://dotnetjunkies.com/weblog/chris.taylor
> > "student" <mr_chat123@.yahoo.com> wrote in message
> > news:24HBd.9293$by5.9098@.newssvr19.news.prodigy.co m...
> > > Hello all, I have this problem in this code I am studying.
> > > I'm getting this error saying that Server Error 'in
> > > '/mcsdWebApps/Chapter5/DBruntime' Application.
> > > Object reference not set to an instance of an object. It says the
error
> is
> > > on line 39 which is
> > > Dim rowInsert As DataRow = dsContacts.Tables("Contacts").NewRow
> > > Thanks in advance for any help!
> > > > Here is the full code:
> > > Private Sub Page_Load(ByVal sender As System.Object, _
> > > ByVal e as System.EventArgs) Handles MyBase.Load
> > > '1. Create the data connection.
> > > Dim ContactMgmt As New SqlConnection _
> > > ("Server=(local);database=Contacts;Trusted_Connectio n=yes")
> > > 'Create an adapter.
> > > Dim adptContactMgmt As New _
> > > SqlDataAdapter("select * from Contacts", ContactMgmt)
> > > '2. Create a data set.
> > > Dim dsContacts As New DataSet()
> > > 'Set select command.
> > > adptContactMgmt.SelectCommand.CommandText = _
> > > "SELECT * FROM Contacts"
> > > '3. Create, insert, delete, and update commands automatically.
> > > Dim cmdContactMgmt As SqlCommandBuilder = New _
> > > SqlCommandBuilder(adptContactMgmt)
> > > '4. Create a new row.
> > > 'HERE'S WHERE I'M GETTING THE ERROR!
> > > Dim rowInsert as DataRow = dsContacts.Tables("Contacts").NewRow
> > > 'Add data to fields in the row.
> > > rowInsert("ContactId") = 3
> > > rowInsert("FirstName") = "Mary"
> > > rowInsert("LastName") = "Smith"
> > > rowInsert("WorkPhone") = "(444) 222-2222"
> > > 'Add the row to the data set.
> > > dsContacts.Tables("Contacts").Rows.Add(rowInsert)
> > > '5. Update the database.
> > > adptContactMgmt.Update(dsContacts.Tables("Contacts"))
> > > End Sub
> >
Object reference not set to an instance of an object (problem using fileupload in codebehi
I am using file upload and when tying to get the uploaded file it is saying "object reference not set to an instance of an object" I even tried to get the control but still no luck. Can anybody give the solution for this. I have searched many topics related to this forum and even in web but nothing seems to working. Posting my code below,
upload.aspx
<
asp:ViewID="loadingData"runat="server"><asp:ImageID="Image2"onmouseover="changeTabPicture(id)"onmouseout="changeTabPictureBack(id)"runat="server"ImageUrl="~/Images/SelectOff.gif"/><asp:ImageID="Image4"runat="server"ImageUrl="~/Images/LoadOn.gif"/><asp:ImageID="Image9"onmouseover="changeTabPicture(id)"onmouseout="changeTabPictureBack(id)"runat="server"ImageUrl="~/Images/EditOff.gif"/><asp:ImageID="Image10"onmouseover="changeTabPicture(id)"onmouseout="changeTabPictureBack(id)"runat="server"ImageUrl="~/Images/FinalizeOff.gif"/><br/><asp:WebPartZoneID="LoadingWebPart"runat="server"BorderColor="#CCCCCC"Font-Names="Verdana"Padding="6"><ZoneTemplate><asp:PanelID="uploadPanel"runat="server"Height="50px"Width="125px"Enabled=true>"align="left"bgcolor="lemonchiffon"border="1"bordercolor="firebrick"style="height: 158px"visible="true"width="180"><asp:FileUploadID="OFDSelectFile"runat="server"Width="286"Enabled=true/>
<asp:button id="button1" runat=server onClick="Submit_Click"/>
</zonetemplate>upload.aspx.cs
protected void submit_click(object sender, evenetargs e)
{
string filepath = OFDSelectFile.PostedFile.FileName; //it gives error in this place
}
Let me know as soon as possible I have a demo to do on monday.
Are you declaring your OFDSelectFile at the top of your code-behind page? When you add a control to your HTML page it isn't added to the code-behind unless you flip your HTML to design-view. It's a little gotcha thing. If you are not declaring your OFDSelectFile at the top then add it manually, or try the design view trick.I tried to define soemthing like this "protected System.Web.UI.WebControls.FileUpload OFDSelectFile;" on the code-behind but it says the page already has the definition for it. Can you please elaborate on how to use it or if there is any other trick please let me know.
dev_discuss:
I tried to define soemthing like this "protected System.Web.UI.WebControls.FileUpload OFDSelectFile;" on the code-behind but it says the page already has the definition for it. Can you please elaborate on how to use it or if there is any other trick please let me know.
You may want to turn on Tracing and look int he "Control Tree" to confirm that the generated ID of the control indeed is *just* "OFDSelectFile"
for info on ID's and Naming Containers, check out this good article:
http://odetocode.com/Blogs/scott/archive/2006/03/12/3091.aspx
Hi,
I am not sure completely how to get the id of the control, I had this code worked on other aspx page but I integrated my code with other and it is at that point it started not to work. One difference I found when I moved the code in the code behind I had something like "public partialclass Import : System.Web.UI.UserControl" for which the above code was working but when I copied and pasted my code in another page which had "public partial class _Default:Syste.web.ui.page" and the above code is not working .
I am not sure whether this is the reason it is not working because I had this code working in other pages.
Please let me know if you have any idea about this.
File upload was not working because I was usign it inside atlas update panel. If I use it outside then everything works fine.