Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.net 2.0 scripting 1

Status
Not open for further replies.

bouwob

Programmer
Apr 12, 2006
171
US
I have a user control that requires a call to the database with veriables.

Code:
<uc1:filter id="list" runat="server" DropDownName="Mylist" FilterStoredProc="[b]<% string[] tmpData = Session["userInfo"].ToString().Split(','); Response.Write(string.Format("exec sp_GetMyList '{0}'", tmpData[2])); %>"[/b] >

problem is the script does not work. How do I accomplish within the aspx page. If this is not possable how would I go about doing something like this.

TIA
 
problem is the script does not work.
What do you mean? Are you expecting the above code to execute your stored procedure and write the results out to the page?


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
soory for the above.

How about this.

After tincering I found that the code I need to write has to occur in the cs file.

So I wrote this little peice

Code:
        protected void lstUserApps_Init(object sender, EventArgs e)
        {
            string[] tmpData = Session["userInfo"].ToString().Split(',');
            string filterstoredproc;
            filterstoredproc = String.Format("sp_GetUserApps '{0}'", tmpData[2]);
            lstUserApps.FilterStoredProc = filterstoredproc;

        }

problem with this is that the even is called after the control is created.

So my next ide is to do it in the page_init event if I can figure out where or how exactly to do that. (VS doesnt seem to give events for the entire page.

When you double click you get the page_load built for you.

but I believe that I need to place my work here
Page initialization
During page initialization, controls on the page are available and each control's UniqueID property is set. Any themes are also applied to the page. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.)


so new question. How do I set up an event handler for page initialization????
 
oh and script does not work means that the HTML looks like this

<uc1:filter id="list" runat="server" DropDownName="Mylist" FilterStoredProc="<% string[] tmpData = Session["userInfo"].ToString().Split(','); Response.Write(string.Format("exec sp_GetMyList '{0}'", tmpData[2])); %>" >

and not this

<uc1:filter id="list" runat="server" DropDownName="Mylist" FilterStoredProc=""exec sp_GetMyList 'user'" >
 
In VS, on the top of the code-behind page there are 2 drowdowns. In the left dropdown, select "page events", then in the right dropdown, select the event you want to create.
 
private void Page_Init(object sender, EventArgs e)
{
}


did the trick. This still does not seem to work though because the control is built befor the page_init hits. (So the filter control does not load the correct information)

My next thoughts

Is there a way to refresh a control? This presumably should work since it will reload with the spacific attriblutes already set.
 
I am unclear on what you are trying to do. If you need to show data in your usercontrol, then you write the database call there. I would put it in the Page_Load of the user control. From the page, that contains the UC, you can pass any paramters you need to the UC.
 
The database call is in the user controll, but it was written as a generic control. Therefor I need to tell the user control what call to make. The problem with this current situation is that the call to the database will be dynamic depending on the person using the page.

so if I would do FilterStoredProc="exec sp_GetMyList 'testuser'" it would work correcty if test user was the only person touching the page. But unfortunatly 1000's of people are using it and I get the value for AD. So I need to know how to call the generic control with a dynamic value for FilterStoredProc.

I can set the correct thing in the code behind but cant seem to figure out how to set it befor the control builds itself. Which lead me to believe if I could refresh the control everything would be fixed.


Does this help you out any better????
 
The way I would approach this would be to set a property on the page, then access that property(username) from the UC's Page_Load event and use that as a parameter for the sql call.
 
This still leaves me at where we currently are because the control is built befor the Page_Load and Page_init are run on the calling page. As to putting the property in the user control it would work ok for this one instance but kind of defies the purpose of the control since next time I might need to find users based on a certain program. or programs based on a certain platform. or platforms based on a certain group. etc,etc,etc. Which means I will have to add a new function and alot of code on every different use of the control.

fortunatly this is the first time I have run into the issue and the control is being used in 100's of other spots. The only difference here is that I need to add a dynamic value to the FilterStoredProc property on the page.

the rest are using sp's that say grab all platforms, applications, countries, etc. Where I can just call the sp with no veriables.

So last question I can think of is should I just hard code this user control in this one instance and hope I never need to have a dynamic call? (which I am not thrilled about since the same code will be in 2 places). I am deffinatly against setting up a bunch of properties in the user control since it could amount to a large amount of them and decentralize the work that should be done on the calling page.
 
I think you should take a step backwards here to work out the page life cycle.

Forget about the user control you have now, and also the page that hosts it. Create a completely new test project, with a user control that simply writes out a value. Then, drop the user control on the page and we'll take it from there. Post the relevant files here to demonstrate the test, show what you want to do and then we can copy the test files and explain the best method to acheive what you want.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
actually I just figured it out. The user control needed a refresh methed that would rewrite the control. I just call that after I set the propert and it now works fine and dandy.

Next time I need to use this it doesnt matter when I set the filterstoredproc property as long as I immediiatly call the refresh aftwards. This will keep the work where it needs to be and will not affect the 100 other filters already in place.

ps. Thanks for your help. Made a big difference in getting to pound my head on the desk in the correct mannor and find the perfect solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top