Showing posts with label input. Show all posts
Showing posts with label input. Show all posts

Monday, March 26, 2012

Pass values from one user control to a user control on a different aspx page

Hello,

I have an aspx page titled Search.aspx. Within this page, I have a user control titled Search.ascx. I want a user to input search terms, then on the click of a button, I want to pass the values to another page (SearchResults.aspx)...which will then display the results in a user control.

Can someone please give me some suggestions on how to do this?

Thanks a lot!Hello, what you can do is:

inside ur usercontrol, create a method that returns a dataset or datareader. that is, since u are searching using the usercontrol, then the result of ur search will be returned by a method of type either dataset or datareader.

and in ur code-behind of the aspx page u can use it as follows:

protected Myusercontrol user;
private DataSet ds = user.GetResults();

and then u might want to put it in a session variable or xml file and then u will be able to access it from the SearchResults.aspx

but why do u want to show results in another page ?

Saturday, March 24, 2012

passing 30+ parameters

i am developing a asp.net aplication, in that..Form1 has some 30 plus text input boxes.

i use a business logic to insert data into the database,

What will be the optimal way to pass all these parameters to BusinessLogic in a single function call?

Hi

I create a structure and fill up the details and then pass it to the business logic and this works very well for me.

I suggest, you try this approach.


Usually for most of my web apps I create a data access layer (DAL) that is a seperate DLL.

I have all my data modelled in objects and pass only the objects back and forth to the DAL. I sometime mix in the business logic layer (BLL) into the DAL as well depending on how complex the application is. One advantage to this is it is quite easy to slap on any type of a GUI onto you application since the core of the application lives is in the DAL or DAL & BLL.

It will make your life easier maintaining the code in the future as well.


so is it advicable to send them in object arrays

Yes.

You could use generics (templates) to pass them if you like.

List<yourObject> type.


sorry, i dont follow your last post. can you give a sample for say 6 diferrent objects

You can use something like the following:

List<String> myStringList = new List<String>();

myStringList.Add("String1");

myStringList.Add("String2");

Generic type will ensure that you are only inserting the String and not any other object. If you have different objects that you will be inserting you can use an ArrayList or better off List<object>.


List<String> myStringList = new List<String>();

myStringList.Add("Alpha");

myStringList.Add("11 Address");

what is the <String> there?Tongue Tied


String is a type. List<String> means that you are creating a list which will only contain string elements. So, if you have 30 textboxes you can iterate through the textboxes and populate the list. Later if you need to access the values of the textboxes you can put the list into a session variable and then access it on the next page.


List<String> myStringList = new List<String>();

creates a "container" called myStringList which can only host String object. You can put as many String object as you want and pass the List "container" itself as parameter. here is one example.

public ... function (List<string> inputList)
{
...

foreach (string currValue in inputList)
{
// iterate through the List

// Do something

}


return ...;
}


Is the List<String> objectIndexed.

How do i access the individual objects in the list?


It's very simple:

List<string> lstStrings = new List<string>();

lstStrings.Add("Test");

string sTemp = lstStrings[0];

or you could use a foreach

foreach (string sTemp in lstStrings)...


List<string> lstStrings = new List<string>();

i get this error when trying to use that construct

"Error 1 The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)"


add this to the top of your code behind file:

using System.Collections.Generic;


using System.Collections.Generic;using System.Collections.Generic;add this to the top of your code behind file:

using System.Collections.Generic;