Im designing a web site and trying some new concepts. instead of just coding everything onto a web page, i am populating different areas of the page using a database. for example on a news page, i have a drop down to select the story, then I have different areas of the page pull in the headline, story, picture and date which are all stored in the database. everything is working good. the only thing I want to do is clean up the code a little. Id like for all the connection strings and select statements to be stored in a method on a script or something. and preferably on a HTML page, not an aspx page.
I have a decent amount of knowledge with basic HTML, and some experience programming with Visual Basic.net and SQL. I am using Visual studio 2012, putting all of this on an ASPX page.
here is an axample of what i have written and working. this displays the headline of the story based off of the value selected in the “NewsDropDown” Drop list.
<%-- displays the headline --%>
<asp:FormView ID="NewsHeadlineText" runat="server"
DataSourceID="NewsHeadline" class="hdr"
meta:resourcekey="NewsHeadlineTextResource1" >
<ItemTemplate>
<asp:Label ID="HeadlineLabel" runat="server"
Text='<%# Bind("Headline") %>' meta:resourcekey="HeadlineLabelResource1" />
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="NewsHeadline" runat="server"
ConnectionString="<%$ ConnectionStrings:VBallTalksDBConnectionString %>"
ProviderName="<%$ ConnectionStrings:VBallTalksDBConnectionString.ProviderName %>"
SelectCommand="SELECT [Headline] FROM [News] WHERE ([Headline] = ?)">
<SelectParameters>
<asp:ControlParameter ControlID="NewsDropDown" Name="Headline"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
You can use jQuery’s AJAX or a regular AJAX for querying your script that touches the DB in ASP and return the results of the processing in JSON. That way when it comes back you can continue to populate the sections of your website in the programming language of your choice. In PHP with MySQL using AJAX/Javascript and HTML5/CSS3 I have done this in the past with much success, let me know if you have an static mockup in JSFiddle (http://jsfiddle.net/) or JSBin if you decide to use Javascript to address your needs