Pass a string from a .ascx to a .aspx

C

Chad

Alright, I've been searching all over and it seems I'm just not looking
for the right thing, since what I want to do seems extremely simple I
just don't know the correct syntax. All I get is how to pass
information from a control in a .ascx to a control placeholder in the
html section. I don't want to do that.

The following example should explain what I want to do.

..ascx code:
<script runat="server">
Public strConnectString As String =
"server=SQLServer;trusted_connection=true;database=ADatabase"
</Script>

..aspx code:
<script runat="server">
Sub Page_Load
Conn = New SqlConnection(strConnectString)
End Sub
</script>

Basically I just want to use the strings I define in the .ascx in the
..aspx, the reason is I want a .ascx page that contains all
configuration info for every page I use, so that when I move a page to
a different server or if I switch databases I won't have to edit 8
pages just to change 10 or 11 lines of configuration settings.

Thanks to anyone that can help.
Chad
 
J

John Timney \(ASP.NET MVP\)

You probably just need to define a property, set it in the control, and get
it from the page via a declared instance of the control in your aspx page.
However, this is better suited to the web.config file which is designed for
this type of static data and can be read and cached for use globally.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
C

Chad

Thanks guys,
I've read that article once and didn't see what I needed, however since
you have posted it for me I guess I'll actually read it this time,
instead of skimming through it for my answer.

Also, when you say "You probably just need to define a property, set it
in the control, and get it from the page via a declared instance of the
control in your aspx page."

I have some trouble understanding what that means. I guess I need to
go back to my intro to asp.net and re-read on what the definitions of
those terms are.

Anyway, I'll read the openmymind article and read up on the terms you
gave me that way I can finally reach my solution.

Thanks again,
Chad
 
C

Chad

I ended up storing the variables in the web.config like you suggested
John, thanks for making me aware of that option.
 
J

John Timney \(ASP.NET MVP\)

your welcome :)

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top