Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Accessing form objects from Codebehind

Reply
Thread Tools

Accessing form objects from Codebehind

 
 
vbMark
Guest
Posts: n/a
 
      06-29-2004
Hi there,

Using ASP.NET and C# I am trying to access an object on the main form from
the "Codebehind" file default.aspx.cs but can't figure out how.

If I have Textbox1 then how do I put text in it from default.aspx.cs?

Thanks.

--
http://www.vbmark.com/
A good place to start.
 
Reply With Quote
 
 
 
 
Benjamin Bittner
Guest
Posts: n/a
 
      06-29-2004
Hallo vbMark
"vbMark" <(E-Mail Removed)> schrieb im Newsbeitrag
news:Xns95175B0BF1A16noemailcom@130.133.1.4...
> Hi there,
>
> Using ASP.NET and C# I am trying to access an object on the main form from
> the "Codebehind" file default.aspx.cs but can't figure out how.
>
> If I have Textbox1 then how do I put text in it from default.aspx.cs?
>

textbox1.Text = "New Text here",
but before you can do that you have to tell the codebehind module, that
there is a textbox called "textbox1" on the aspx page. im sorry, but i am
not a c# expert, (or c# newbie... ), but in vb, you do it this way:
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
after this you can access every textbox property.

regards benni


 
Reply With Quote
 
 
 
 
Benjamin Bittner
Guest
Posts: n/a
 
      06-29-2004
Hallo vbMark
"vbMark" <(E-Mail Removed)> schrieb im Newsbeitrag
news:Xns95175B0BF1A16noemailcom@130.133.1.4...
> Hi there,
>
> Using ASP.NET and C# I am trying to access an object on the main form from
> the "Codebehind" file default.aspx.cs but can't figure out how.
>
> If I have Textbox1 then how do I put text in it from default.aspx.cs?
>
> Thanks.
>
> --

The c# declaration is:

protected System.Web.UI.WebControls.TextBox TextBox1;

regards benni


 
Reply With Quote
 
mortb
Guest
Posts: n/a
 
      06-29-2004
Something like:

file "page.aspx:":

<asp:textbox id="myTxt" runat="server"/>

-----------------------------------------------------
codebehind file "page.aspx.cs":

namespace XX
{
public class myPage
{
protected TextBox myTxt;

private void Page_Load(object sender, System.EventArgs e)
{
myTxt.Text = "Hello world!"
}
}
}
------------------------------------------------
cheers,
mortb

"vbMark" <(E-Mail Removed)> wrote in message
news:Xns95175B0BF1A16noemailcom@130.133.1.4...
> Hi there,
>
> Using ASP.NET and C# I am trying to access an object on the main form from
> the "Codebehind" file default.aspx.cs but can't figure out how.
>
> If I have Textbox1 then how do I put text in it from default.aspx.cs?
>
> Thanks.
>
> --
> http://www.vbmark.com/
> A good place to start.



 
Reply With Quote
 
vbMark
Guest
Posts: n/a
 
      06-29-2004
I had the code in a function like this:

public static void DoThing ( )
{
myTxt.Text = "Hello world!"
}

And it did not work but does work in Page_Load. Why is that?

Thanks.


"mortb" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> Something like:
>
> file "page.aspx:":
>
> <asp:textbox id="myTxt" runat="server"/>
>
> -----------------------------------------------------
> codebehind file "page.aspx.cs":
>
> namespace XX
> {
> public class myPage
> {
> protected TextBox myTxt;
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> myTxt.Text = "Hello world!"
> }
> }
> }
> ------------------------------------------------
> cheers,
> mortb
>
> "vbMark" <(E-Mail Removed)> wrote in message
> news:Xns95175B0BF1A16noemailcom@130.133.1.4...
>> Hi there,
>>
>> Using ASP.NET and C# I am trying to access an object on the main form
>> from the "Codebehind" file default.aspx.cs but can't figure out how.
>>
>> If I have Textbox1 then how do I put text in it from default.aspx.cs?
>>
>> Thanks.

 
Reply With Quote
 
mortb
Guest
Posts: n/a
 
      06-30-2004
Is the function DoThing called somewhere? From where?
If you add a call to DoThing in Page_Load I'm sure it will work

cheers,
mortb


"vbMark" <(E-Mail Removed)> wrote in message
news:Xns95176407D5268noemailcom@130.133.1.4...
> I had the code in a function like this:
>
> public static void DoThing ( )
> {
> myTxt.Text = "Hello world!"
> }
>
> And it did not work but does work in Page_Load. Why is that?
>
> Thanks.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Accessing a container objects state from aggregated objects Derek Basch Perl Misc 4 08-16-2006 09:04 AM
Accessing a usercontrol from parent codebehind Mat ASP .Net 4 10-29-2004 02:00 PM
Accessing JavaScript function in codebehind Vinod Kumar ASP .Net 5 12-29-2003 04:09 AM
Problem accessing UserControl properties from ASP.NET Web Form CodeBehind jdn ASP .Net Web Controls 3 09-17-2003 11:39 PM



Advertisments