Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 7th, 2007, 07:42 AM
Authorized User
 
Join Date: Nov 2006
Location: Bangalore, Karnataka, India.
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Somesh
Default how to get the control in runtime in asp.net page

Hi All
I have a page in which the controls (Checkboxes, Textboxes, and Dropdown List) are created programmatically. There is a Button, by clicking it I need to separate the Textboxes and the conditions from the Dropdown List.

My problem is that is why whenever the program is not running then there is no existence of the above said controls that is why when ever I am trying to run the code, the compiler is sending some errors like this: - The CheckBox1 does not exist in the current context.

How can I over come this problem?

I shall be highly obliged if I get any type of suggestion from any one.

With Regards.



someshchaterjee
__________________
somesh chaterjee
  #2 (permalink)  
Old March 7th, 2007, 09:45 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. the compiler is rigth.. you haven't got that controls yet.

Since you are creating that controls on runtime, you will have to find a method to call them without knowing there Id. For example you could use findcontrols to find the one you are looking for and cast that object to the specific type.

You create controls when you really not know how many of them will you need or in cases that the controls match an external data sources. If you know that the control will be there always and the name of it, then you just not create it on runtime and put it on the form at design time.

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
  #3 (permalink)  
Old March 7th, 2007, 10:45 AM
Authorized User
 
Join Date: Nov 2006
Location: Bangalore, Karnataka, India.
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Somesh
Default

Hi HTH
Glad to get your reply. Thanks for it.

i am sending you the algo left by me. Can you give some suggestion for the parf:-
for (i=0;i<x;i++)
{
if(checkboxi.checked==true)
{

Do some work with this code.
}
}
 of the Algo.

Algo:-
Button click
{
    for (i=0;i<x;i++)
             {
if(checkboxi.checked==true)
{

Store the name field corresponding to the checkbox field into an array.
Store the filter condition corresponding to the checkbox field into an separate array.
}
           }
Sql Query:- Will be generate programmatically:-
 Sql Query:- ASelect[fetch the array element and separate these by , by a loop] from table name(i.e. SQLDataSource1(which can be insert in GUI mode))[fetch the filter condition from the 2nd array the element will be separated by ,]

• Declare a seasonal variable and store the resultant string into it.

Call the next page.
}


Next Page:-

{
    Get the data from the seasonal variable and print it.
}


Bye Somesh

someshchaterjee
  #4 (permalink)  
Old March 7th, 2007, 10:53 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

HTH: Hope this help ;) my name is gonzalo

I don't understand where do you need my help.. you have the pseudocode already done..

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
  #5 (permalink)  
Old March 7th, 2007, 10:59 AM
Authorized User
 
Join Date: Nov 2006
Location: Bangalore, Karnataka, India.
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Somesh
Default

Hi gonzalo
I need your help in the area where the code will check the checkbox is checked or not. i am not getting how can I do that part?
Somesh

someshchaterjee
  #6 (permalink)  
Old March 7th, 2007, 11:14 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

mmm.. excuse me.. but you are trying to read every checkbox using
checkboxi where i is part of the name of the checkbox??
First of all since this is asp.net the control will render to the page with the id that you give to it when you create it.
Second you can't reference a control that way since the compiler will think that the name of the control is checkboxi and will not know that that particular i should be a number since looks like part of the name.
the best aproach you have it's to do a findcontrol where you can do something like "checkbox" & i.tostring and it will resolve the control ok.

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
  #7 (permalink)  
Old March 7th, 2007, 11:33 PM
Authorized User
 
Join Date: Nov 2006
Location: Bangalore, Karnataka, India.
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Somesh
Default

Thank you Gangalo.

I shall try in this way. If I be sucessfull I shall inform you.

With Regards
Somesh

someshchaterjee


Similar Threads
Thread Thread Starter Forum Replies Last Post
using asp.net web user control in asp 3.0 App i_shahid Classic ASP Professional 0 January 8th, 2008 07:32 AM
access C#.Net page as action of calssic ASP page mansharma_s ASP.NET 1.x and 2.0 Application Design 6 January 7th, 2008 10:58 AM
ASP.NET - Static Page and Dynamic Page sohrabus ASP.NET 2.0 Professional 2 April 18th, 2007 11:42 PM
ASP page Runtime Error Cinderella Classic ASP Basics 2 June 4th, 2004 12:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.