Linq - C# - Loop Through Certain Controls On A Page?

Feb 25, 2011

I am currently looping through all the controls on my page and setting certain types (TextBox, CheckBox, DropDownList, etc.) to Enabled=False under certain conditions. However I notice an obvious page load increase looping like this. Is it possible to only get certain types of controls from the Page.Controls object rather than Loop through them all? Possibly with something like LINQ?

View 3 Replies


Similar Messages:

ADO.NET :: Loop Over All Fields In Record - Linq?

Dec 31, 2010

I try to access to the fields of each single record in the table without writing the specific name of the field,

For example , checking each property of the record whether it's null or not,

something like that:

var myUser = from u in dataContext.Users
select u;
foreach (User item in myUser)
{
// Here I wand to access to the fields by their ordinal number.
}

View 2 Replies

ADO.NET :: How To Retrieve Record From Linq Using Forech Loop

Jan 3, 2011

DataClasses1DataContext dc = new DataClasses1DataContext();
var q =
from a in dc.GetTable<Order>()
where a.CustomerID.StartsWith("A")
select a;
}

i have run this query but through using dataGridView1.DataSource = q;

i have get the out put

but i want to select each record through loop because i want to store it in variable

View 2 Replies

C# - Convert Foreach Loop To Linq (in Datagridview)

Jul 21, 2010

foreach (GridViewRow row in gridView.Rows)
{ // Access the CheckBox
CheckBox cb = (CheckBox)row.FindControl("SuburbSelector");[code]....

I tried the following and got error

Linq:

var Str = SuburbGridView.Rows.Cast<GridViewRow>().Where(r=>(CheckBox)r.FindControl("SuburbSelector")==checked);

Error:

Delegate 'System.Func < System.Web.UI.WebControls.GridViewRow,int,bool>' does not take 1 arguments

View 3 Replies

C# - Optimize Code - Linq And Foreach Loop 15k Records?

Sep 6, 2010

this is my code

[code]....

basically, the InstellingGegevens table gest filled in by some procedure from another server.
the thing i then need to do is check if there are new records in this table, and fill in the new ones in Instellingens.

this code runs for like 4 minutes on 15k records. how do I optimize it? or is the only way a Stored Procedure?

this code runs in a timer, running every 6h. IF a stored procedure is best, how to I use that in a timer?

[code]....

View 3 Replies

C# - Loop Through All The User Controls On A Page?

Apr 13, 2010

Want to loop through all the user controls that exist on the page and get their IDs. How do I do it?

View 3 Replies

Javascript To Loop Through All Asp:Hyperlink Controls On A Page And Hide Them

Sep 21, 2010

I have a master page which has a DIV with asp:Hyperlink controls functioning as the menu for the site. When I'm on a certain page if (document.title = 'Certain Page'), I want javascript which will loop through all asp:hyperlink controls on the page and hide them (i.e. set to not visible). I know I could probably do this on the server side with less effort, but I'd rather do it via javascript.

View 3 Replies

Forms Data Controls :: Loop Through All Gridviews On Page?

May 26, 2010

I am trying to loop through all gridviews on a page to hide them and set their page index to 0. This should be very easy to do and it seems like the code below should work but it doesn't?? How can I accomplsh this with the least amount of code? FYI- this code is executed on a button click.

foreach (Control childControl in Page.Controls)
{
if (childControl is GridView)
{
((GridView)childControl).Visible = false;
((GridView)childControl).PageIndex = 0;
}
}

View 4 Replies

Web Forms :: Loop Through Controls To Find Radiobuttonlist Control In Content Page?

May 17, 2010

have been trying to find radiobutton list in my content page which is in an update panel with no luck. I tried the below code:

Dim content As ContentPlaceHolder =
DirectCast(Me.Master.FindControl("ContentPlaceHolder1"),
ContentPlaceHolder)

[code]...

View 4 Replies

Data Controls :: Loop Through All GridView Rows And Not Only Current Page When Paging Enabled

Oct 9, 2013

I currently have a GridView control on my aspx page with paging enabled and I need to loop through the entire row collection/count to process the selected records. With my current code, it will only loop through the current page of GridView row.

foreach (GridViewRow data in grid.Rows)
{
//here is my code
}

View 1 Replies

DataSource Controls :: Finding Code To Loop Through The Reader And Output The Details On Individual Lines Of The Page

Jan 14, 2010

I'm currently trying to build a html table from the results of a sql data reader. As my table has multiple records, I want the code to loop through the reader and output the details on individual lines of the page. In ASP I have done this in the past using something like

[Code]....

but as I am using data readers I'm not sure what the equivalent is.

View 3 Replies

Using Linq To Get List Of Web Controls Of Certain Type In A Web Page?

Aug 31, 2010

Is there a way to use linq to get a list of textboxes in a web page regardless of their position in the tree hierarchy or containers. So instead of looping through the ControlCollection of each container to find the textboxes, do the same thing in linq, maybe in a single linq statement?

View 2 Replies

Web Forms :: Loop Textboxes By ID In Code Behind Page?

Jan 6, 2010

I need to know how to loop the user input value in textboxes programatically. For example I have 3 rows of textboxes i have programatically generated with id txtCategory1, txtCategory2, txtCategory3. Since I generated all these textboxes programatically I have no idea how many textboxes will be there. I need to do a looping again to get the value user put in into textbox. How can I get the value of textbox by using ID?

View 4 Replies

C# - Loop All HTML Components In The Current Page?

Jul 12, 2010

I wish I could go all the elements of an ASP.Net page (HTML elements) and manipulate its text property / value. How could I do that?

I've been checking, and the property this.Page.Form.Controls apparently gets all the elements, but I would only page elements that caught the event.

I'll put an example of code that I'm currently studying and trying adpater for my needs.

[Code]....

View 3 Replies

Delaring A String Thats Within A Loop Within Another Loop

Jan 14, 2010

Im stuck with declaring a string which is in a loop within another loop.

Dim CompanyDetails As String = ""
Dim CompanyRow As DataRow
For Each CompanyRow In newdt.Rows
CompanyDetails += CompanyRow(1) & " " & CompanyRow(0) & "<br/>"...

How can I get this to see the GetInfo as declared..... since its in a loop within a loop?

View 9 Replies

MVC :: Login Form On Master Page Causing Endless Loop

Nov 15, 2010

I am having trouble with my login form. In the current design I have a login ascx which I am trying to use for the user to login from both the home page (as a box on the left) and on the login page that I will use as part of a checkout process.My login.ascx is a partial view using straight out of the box code for simplicity...

[Code]....

What I am trying to achieve sounded rather simple until I tried to implement it. I can get the login page to come right up if I use Html.EditorForModel rather than Html.RenderPartial, but I can't use Html.EditorForModel on my main page because the main page isn't bound to a model.

What I would like is to show login form on main page. If login fails show the validation summary just like on the Login view. I could live with the user being redirected to the login view, but this wasn't what I had in mind.

View 1 Replies

AJAX :: Numeric UP/Down Extender Causes Infinite Page Load Loop?

Aug 14, 2010

I have fought a bizarre situation for days. Anytime a certain listview loaded the page went into an infinite loop of reloading. I was finally put the listview on a page with nothing else to see if I could isolate the issue.Even with only the folowing code, it continually looped on load even though it brought in the correct data every time.

[Code]....

[Code]....

View 1 Replies

DataSource Controls :: Make A LINQ Databound Record Update Page?

Mar 15, 2010

I am creating a database frontend in aspx/C# using LINQ to MSSQL. It has two pages: a main page which lists all of the records, and a page that appears when the user click the "Edit" button next to one of the list items for the user to edit a record.The database table has about 70 user-editable fields. I need to make the edit page, allowing the user to update/insert records. There are a couple ways I can think of make an edit page:Using a LinqDataSource and FormViewUsing a LinqDataSource and DetailsViewManually retrieve the value for each field and set the value for each field directly from Linq (e.g. "projectIDLabel.Text = Convert.ToString(thisRecord.Project_ID)"What would be the best way to design this?

View 4 Replies

Web Forms :: Insert Values In Textbox On Page Load By Using Loop Or Keys Value?

Jan 31, 2011

Actuall i retrive one row from Database with more than 80 columns on page load. Now i need to fill these data in every control like Text-Box and Combo-Box which i have using on the Page.

My Column Name and My Id of the Textbox or combobox are same. now i need to fill the value in textbox and combobox where coumn name and textbox id are same.

Eg.

(1) TextBox Id's Name :- txtCustName, txtCustNo, txtAddress, etc(More than 80 Column).

now i will be remove the 'txt" from every id.

so it would be seems like CustName, CustNo, Address, etc.

(2) Column Name :- CustName CustNo Address

Values from (Dataset) :- Xyz 123 Abc.......

View 6 Replies

How To Call A JavaScript Function Multiple Times In A Loop On Page Reload With C#

Oct 25, 2010

I'm using the local database functionality in Chrome and Safari and what I do when I want to save this to a remote database is to create a hidden textfield and then using JSON to stringify each row. In the code behind I then parse each JSON object and insert it into the list. What I want to do now is to delete these rows from the local database. I have a JavaScript function called deletePatient:

[code]....

View 1 Replies

Forms Data Controls :: Finding A SQL Server Table From 3.5 Master Page And LINQ To Entities?

Jan 20, 2010

I have placed a textbox, dropdownlist and command button in a section of my master page. The textbox, named txtsearch, will be used to input a search string. The dropdownlist, named ddlsearch, will be used to specify in which field to search in the table, either part name or NSN.

Questions:

What VB code do I use to save the value entered into txtsearch as a search string? How do I pass that value to my entitydatasource? How do I tell entitydatasource to search in either the part name or NSN field based on the value of ddlsearch?

View 1 Replies

DataSource Controls :: Linq To SQL Set Linq Object Propertychanged?

Mar 12, 2010

I am writing a plugin to help with a current ERP system we have that I am not allowed to modify the data structure at all. The table I am dealing with has over 100 columns and I am wanting to set my linq object propertychanged event and submitchanges or do I really have list out each property and set it equal to the new one?Below is an example of what I am trying to do:

[Code]....

View 4 Replies

DataSource Controls :: LINQ To DataSet And LINQ To Object

Mar 9, 2010

txtLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Last_Name.ToString();

Like that I have large number of controls on my form. I have dought, if I assigned like this, db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Last_Name.ToString(); to every control, then I have set of controls like,

ddlSalutation.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Salutation.ToString();
txtLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Last_Name.ToString();
txtFirstName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).First_Name.ToString();
txtMI.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Middle_Initial.ToString();
txtAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Home_Address.ToString();
txtCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).City.ToString();
ddlState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).State.ToString();
txtZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Zip_Code.ToString();
txtSSNo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ssn.ToString();
txtMRNo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Mr_No.ToString();
txtDOB.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Birth_Date.ToString();
RBGender.SelectedItem.Value = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Gender.ToString();
RBMaritalStatus.SelectedItem.Value = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Marital_Status.ToString();
txtHomePhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Home_Phone.ToString();
txtWorkPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).WorkPhone.ToString();
txtCellPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).CellPhone.ToString();
ddlSuffix.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Suffix.ToString();
txtReligion.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Religion.ToString();
txtEmail.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Email.ToString();
txtSSOName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ssn.ToString();
txtPatientKin.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Patient_Kin.ToString();
txtRelationWithPatient.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Kin_Relation.ToString();
txtPhoneNo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Kin_Phone.ToString();
ddlPreferredPharmacy.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Id_Pharmacy.ToString();
txtEmergencyContactName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Emergency_Contact_Name.ToString();
txtEmergencyContactNumber.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Emergency_Contact_Phone.ToString();
txtRelation.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Kin_Relation.ToString();
txtRace.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Race.ToString();
ddlHowDidPatientFindUs.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).How_Found.ToString();
txtEmployerName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_Name.ToString();
txtEmployerOccupation.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_Occupation.ToString();
txtEmployerPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_Cell_Phone.ToString();
txtEmployerAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_Address.ToString();
txtEmployerCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_City.ToString();
ddlEmployerState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_State.ToString();
txtEmployerZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Employer_Zip.ToString();
txtRecordsReleasedTo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Records_Released_To.ToString();
txtOtherInfo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Other_Info.ToString();
txtPopupNote.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Popup_e.ToString();
ddlPPlanName.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Insurance_Name.ToString();
txtPGroupNo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Group_No.ToString();
txtPIDNo.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Id_No.ToString();
txtPPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Plan_Phone.ToString();
txtPVerifiedWith.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Verified_With.ToString();
txtPVerifiedPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Verified_Phone.ToString();
txtPEffectiveDate.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Effective_Date.ToString();
txtPExtDate.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Ext_Date.ToString();
if (db.usp_ATI_FetchPatientDetails(iPatientID).Count() > 0)
{
txtPGLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Name.ToString();
txtPGFirstName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Name.ToString();
txtPGMI.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_MI.ToString();
txtPGBirthGDate.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Dob.ToString();
txtPGAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Address.ToString();
txtPGCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_City.ToString();
ddlPGState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_State.ToString();
txtPGZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Zip.ToString();
txtPGEmployerFirstName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Fname.ToString();
txtPGEmployerLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Lname.ToString();
txtPGEmployerPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Phone.ToString();
txtPGEmployerOccupation.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Occupation.ToString();
txtPGEmployerAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Address.ToString();
txtPGEmployerCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_City.ToString();
ddlPGState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_State.ToString();
txtPGEmployerZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Grn_Emp_Zip.ToString();
ddlPGPatientRelationshipToGuarantor.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Grn_Rel_With_Pat.ToString();
txtPGOtherInsuranceNotes.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Other_Notes.ToString();
txtPGAuthorization.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_Authorization.ToString();
txtPGAob.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(0).Ins_AOB.ToString();
}
if (db.usp_ATI_FetchPatientDetails(iPatientID).Count() > 1)
{
txtSGLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Name.ToString();
txtSGFirstName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Name.ToString();
txtSGMI.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_MI.ToString();
txtSGBirthGDate.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Dob.ToString();
txtSGAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Address.ToString();
txtSGCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_City.ToString();
ddlSGState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_State.ToString();
txtSGZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Zip.ToString();
txtSGEmployerFirstName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Fname.ToString();
txtSGEmployerLastName.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Lname.ToString();
txtSGEmployerPhone.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Phone.ToString();
txtSGEmployerOccupation.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Occupation.ToString();
txtSGEmployerAddress.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Address.ToString();
txtSGEmployerCity.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_City.ToString();
ddlSGState.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_State.ToString();
txtSGEmployerZip.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Grn_Emp_Zip.ToString();
ddlSGPatientRelationshipToGuarantor.SelectedItem.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Grn_Rel_With_Pat.ToString();
txtSGOtherInsuranceNotes.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Other_Notes.ToString();
txtSGAuthorization.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_Authorization.ToString();
txtSGAob.Text = db.usp_ATI_FetchPatientDetails(iPatientID).ElementAt(1).Ins_AOB.ToString();
}

My question is that, for each control the Stored Procedure called or not? If it is yes then it is time consuming and I need to use LINQ to DataSet or LINQ to Object rather than to call SP for each control. What is difference between LINQ to DataSet and LINQ to Object?

View 5 Replies

How To Do For Loop With Controls

Mar 9, 2011

For Each Control In Page.Header.Controls How can I do something as above, at the moment getting the error "Control is a Type and Cannot be used as an expression" The Complete Code is as follows Try ' I only do this on my production servers, so I declare those here.'

If Request.ServerVariables("server_name") = [URL] Then
' Allow scripts and css to logged in CMS users'
Dim checkLogin As New Controls.Login
If checkLogin.IsLoggedIn <> True Then
For Each Control In Page.Header.Controls
If Control.GetType.Name = "EktronJsControl" Or Control.GetType.Name = "EktronCssControl" Or Control.GetType.Name = "EktronModalCss" Then
Page.Header.Controls.Remove(Control)
Else
' Removes the extra bubble inline style stuff that wasn't put in a CSS.''
Dim litControl As LiteralControl = Control
If litControl.Text = Nothing Then
litControl.Text = ""
End If
' Removing blank.css file'
Dim htmlLink As HtmlLink = Control
If htmlLink.Href = "/css/blank.css" Then
Page.Header.Controls.Remove(Control)
End If
End If
Next
End If
End If
Catch ex As Exception
End Try`

View 5 Replies

C# - Loop Through All Controls On Webpage

Nov 23, 2010

I need to loop through all the controls in my asp.net webpage and do something to the control. In one instance I'm making a giant string out of the page and emailing it to myself, and in another case I'm saving everything to a cookie. The problem is masterpages and items with collections of controls inside them. I want to be able to pass in a Page to the method, then have that method be generic enough to loop through all controls in the inner-most content page and work with them. I've tried doing this with recursion, but my recursion is incomplete. I want to pass a Page object into a method, and have that method loop through all controls in the innermost content page. How can I achieve this?

private static String controlToString(Control control)
{
StringBuilder result = new StringBuilder();
String controlID = String.Empty;
Type type = null;
foreach (Control c in control.Controls)
{
try
{
controlID = c.ID.ToString();
if (c is IEditableTextControl)
{
result.Append(controlID + ": " + ((IEditableTextControl)c).Text);
result.Append("<br />");
}
else if (c is ICheckBoxControl)
{
result.Append(controlID + ": " + ((ICheckBoxControl)c).Checked);
result.Append("<br />");
}
else if (c is ListControl)
{
result.Append(controlID + ": " + ((ListControl)c).SelectedValue);
result.Append("<br />");
}
else if (c.HasControls())
{
result.Append(controlToString(c));
}
//result.Append("<br />");
}
catch (Exception e)
{
}
}
return result.ToString();
}
Without Try/catch
Object reference not set to an instance of an object.
On line controlID = .....

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved