|
 |
aspdotnet_website_programming thread: Problem: Object reference not set to an instance of an object
Message #1 by vop@i... on Mon, 11 Mar 2002 14:40:23
|
|
Hi there, I have problem with accessing value in TextBox. Here is my
source code:
<asp:DataGrid id="EditNewsGird" AutoGenerateColumns="False"
ShowFooter="False" ShowHeader="False" CellPadding="0" CellSpacing="0"
Runat="server" GridLines="None">
<Columns>
<asp:TemplateColumn>
<ItemStyle VerticalAlign="Top"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="ActNewsBox" Runat="server" Height="75px"></asp:TextBox>
<asp:Button ID="odoslat" Runat="server" Text="Save"
OnClick="odoslatBtn_Clik"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
CodeBehind:
protected DataGrid EditNewsGird;
protected TextBox ActNewsBox;
protected Button Odoslat;
private void Page_Load(object sender, System.EventArgs e) {
string id = Request.QueryString["id"];
SqlConnection Spojenie = new SqlConnection
("Server=localhost;Database=gamesland;uid=sa;pwd=sa");
FillNews(sender, e, Spojenie); // -- runnig some function
if (id != null) {
EditNews(sender, e, Spojenie, id); // -- runnig some function
}
}
public void odoslatBtn_Clik(object sender, System.EventArgs e) {
if (Page.IsValid) {
string someString = ActNewsBox.Text;
Response.Write("UPDATE");
//Here I want to acces the value of TextBox ... but i received this one:
//NullReferenceException: Object reference not set to an instance of an
//object
//TextBox value come from MSSQL db ... i want submit and access the value
}
}
Message #2 by vop@i... on Mon, 11 Mar 2002 14:50:25
|
|
ok ... i know the problem now ... so the answer is ... how can i access
server control which is nested under server control? ... TextBox is nested
in DataGrid ...
Message #3 by "Lewis Bass" <lewis@t...> on Tue, 12 Mar 2002 09:08:02 -0700
|
|
I have a similiar problem - and could not realy find a good solution, but
came up with a terrible hack.
IF ANYONE HAS A BETTER SOLUTION I AM INTERESTED ALSO!
1) I changed my template column to work like below
<ASP:TEMPLATE COLUMN >
<ITEMTEMPLATE>
<%# DO_TEXT(DATABINDER.EVAL(CONTAINER.DATAITEM, "SHOWNUM") %>
<ITEMTEMPLATE>
2) I wrote a procedure called do_text
Public Function do_text(ByVal TextName As String, ByVal DefaultValue As
String, ByVal FieldWidth As Integer) As String
' this function is a wrapper because the html page can not seem to call
' the function directly when it is in an external module
' i wish this was different but can not find any other solution...
' (at least i used a wrapper for this terrible hack......)
Dim num As String
num = Trim(Session(TextName))
Session(TextName) = Session(TextName) + 1
TextName = Trim(TextName) & Trim(num)
do_text = Html_Text(TextName, DefaultValue, FieldWidth)
End Function
this returns a string like - <input type="text" name=requestname0">
3) To access the value use response.redirect("requestname0")
I know that this is a terrible approach - but it is the best that I could
do - and it allowed me to
use a datagrid to input all of the fields - hope it helps
----- Original Message -----
From: <vop@i...>
To: "Website Programming with ASP.NET"
<aspdotnet_website_programming@p...>
Sent: Monday, March 11, 2002 2:50 PM
Subject: [aspdotnet_website_programming] Re: Problem: Object reference not
set to an instance of an object
> ok ... i know the problem now ... so the answer is ... how can i access
> server control which is nested under server control? ... TextBox is nested
> in DataGrid ...
$subst('Email.Unsub').
Message #4 by vop@i... on Tue, 12 Mar 2002 16:43:44
|
|
thanx ...
but ... this is something like drilling teeth through ******* :))) ... but
my "solutions" were also something like it ... i try to solve it through
client-side javascript (textboxes where in DataGrid but i had some input
boxes out of datagrid and through javascript i took the value of textboxes
and filled it into input boxes ) ...
i hope that someone has better solution ...
Message #5 by "Lewis Bass" <lewis@t...> on Wed, 13 Mar 2002 08:20:43 -0700
|
|
Datagrid are excellent for the display of data!
but the stink when it comes to ANYTHING else.
Sometime when I have nothing to do and would enjoy pounding my head on the
wall
I will try doing a custom control based upon the asp:textbox tags......
----- Original Message -----
From: <vop@i...>
To: "Website Programming with ASP.NET"
<aspdotnet_website_programming@p...>
Sent: Tuesday, March 12, 2002 4:43 PM
Subject: [aspdotnet_website_programming] Re: Problem: Object reference not
set to an instance of an object
> thanx ...
> but ... this is something like drilling teeth through ******* :))) ... but
> my "solutions" were also something like it ... i try to solve it through
> client-side javascript (textboxes where in DataGrid but i had some input
> boxes out of datagrid and through javascript i took the value of textboxes
> and filled it into input boxes ) ...
>
> i hope that someone has better solution ...
$subst('Email.Unsub').
Message #6 by vop@i... on Thu, 14 Mar 2002 08:10:39
|
|
I found the solution ... but with it comes other problem ... the
solution's name is Editable DataGrid ... but ... TextBox value come form
DataSet and after Submit the value didn't change ... Example:
TextBox value form DB: "AAAAA"
I wrote: "AAAABBBB"
Value after submit: "AAAAA" -> the same like before submit
Message #7 by "Sebastian" <ryders2005@m...> on Tue, 19 Mar 2002 13:49:27
|
|
Just to let you know guys, you can access datagrid items (like your
textboxes) this way:
yourdatadrig.Items(<zéro-based line index number>).Controls(<find the text
box index control or use FindControl>)
then use
CType ( <this this up here...>, TextBox).Text and you go it... ;)
M&M's are better than Money because you can eat them! : o
l8r
Ryders
Message #8 by "Lewis" <lewis@t...> on Tue, 19 Mar 2002 07:39:16 -0700
|
|
THANK YOU FOR THE INFO!
I have been looking for a way to do this for some time, but do not fully
understand.
Could you send me an example?
-----Original Message-----
From: Sebastian [mailto:ryders2005@m...]
Sent: Tuesday, March 19, 2002 1:49 PM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] Re: Problem: Object reference
not set to an instance of an object
Just to let you know guys, you can access datagrid items (like your
textboxes) this way:
yourdatadrig.Items(<zéro-based line index number>).Controls(<find the text
box index control or use FindControl>)
then use
CType ( <this this up here...>, TextBox).Text and you go it... ;)
M&M's are better than Money because you can eat them! : o
l8r
Ryders
Message #9 by vop@i... on Tue, 19 Mar 2002 15:02:20
|
|
Try this one:
protected DataGrid EditCompany;
public void WriteFirma_Click(object sender, System.EventArgs e) {
string IDFirma = Request.QueryString["id"];
Control cFirmaBox = EditCompany.Items[0].FindControl("FirmaBox");
string TextFirma = ((TextBox) cFirmaBox).Text;
Control cFirmaTyp = EditCompany.Items[0].FindControl("TypList");
string FirmaTyp = ((DropDownList) cFirmaTyp).SelectedItem.Value;
Control cLinkBox = EditCompany.Items[0].FindControl("LinkBox");
string LinkFirma = ((TextBox) cLinkBox).Text;
}
|
|
 |