Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gareth Bradley 30 posts 41 karma points
    Feb 02, 2009 @ 18:14
    Gareth Bradley
    0

    Templating ASCX Usercontrol Search Results

    Hi All,
    I am developing a classified ads extension for umbraco, which I will package and release to the community when done. The idea is that it is 100% umbraco - for instance, no custom database tables are required. I achieve this by using a document type with the information I need such as price, location, title, content etc and search through that.

    Now, I had a ASP.NET usercontrol handling the search, and search results. This worked well, but the style of the results are fixed, and only modified via the source. As I want to release this to the community, that isn't acceptable.

    My next version used and ASP.NET usercontrol to make a themeable search panel (keywords, min/max price) and the "Search" button sets all of the search terms into session variables. The control would then refresh the page and an XSLT "search" macro would grab variables from the session object and conduct the search.

    This works well, but suffers two problems:
    * The keywords search syntax is limited to phrases, as I could only use the XSLT "contains" function against the description and title.
    * Unable to use AJAX to load the results without a page refresh.

    So, the desired effect is to be able to customize the search results of an ASCX macro. Ideally, the ASCX would do the search, find relevant nodes and call an XSLT macro for each result. The XSLT macro would contain the code for a single search result.

    The other way is extensive CSS theming, but what if someone else wanted to add a property to the document type? They would need to modify the search control to display that info. Calling an XSLT macro per result would allow anyone to do that themselves.

    Ideas anyone?!

    Thanks
    Gaz

  • Gareth Bradley 30 posts 41 karma points
    Feb 08, 2009 @ 21:01
    Gareth Bradley
    0

    bump?

  • Gareth Bradley 30 posts 41 karma points
    Feb 09, 2009 @ 15:28
    Gareth Bradley
    0

    Last try...Any ideas?!

    Thanks

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Feb 09, 2009 @ 20:52
    Dan Diplo
    0

    Have you ever used the old umbSearch package? Basically it is a search control (that utilises Lucene.NET) and it can format the search results as part of the user control rendering or, alternatively, there is a mode whereby it generates XML on the fly and then references an XSLT style-sheet and uses that to transform the results. The latter method seems to me a good idea - it allows you to use the power of .NET to generate results in XML and then use the flexibility of XSLT to style those results.

    It may be worth downloading the source code from http://www.codeplex.com/umbracoext/SourceControl/ListDownloadableCommits.aspx

    (Note the code doesn't work with Umbraco V4 "as is" but it may give you some ideas. Just look for the umbSearch project).

  • Gareth Bradley 30 posts 41 karma points
    Feb 10, 2009 @ 13:05
    Gareth Bradley
    0

    Great idea! I knew there would be a solution out there. I'll give it a blast this week and post back.

    Thanks for the Heads Up!

    Gaz

  • Gareth Bradley 30 posts 41 karma points
    Feb 11, 2009 @ 18:15
    Gareth Bradley
    0

    Diplo - that was a stroke of genius! It works perfectly.

    I promise to stick to my word. The (very messy) source code will be made public once my wife's site is up and running. Until then, feel free to ask any questions...

    Thanks again,
    Gaz

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Feb 11, 2009 @ 18:32
    Dan Diplo
    0

    Hey, I'm really glad that worked - excellent! Though I can't take credit for the idea - just happy to help. Keep us updated when you release the package, it sounds interesting and useful.

  • Lars 66 posts 136 karma points
    Jan 07, 2011 @ 15:03
    Lars
    0

    Hi! I have ascx files as macros and I have a few tables placed together with the databases of Umbraco on a server. I need a path string to connect to the database: I tried with the path of SQL Management Studio, but it doesn't seem to work. I tried "Data Source=(local);Integrated Security=True" and "data source=127.0.0.1;Trusted_Connection=yes".

    Nothing works. Any suggestons will be highly appreciated!

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Jan 07, 2011 @ 15:57
    Michael Latouche
    0

    Hi Lars,

    If this is a remote SQL server, you should replace "(local)" by the actual IP address of that SQL server. My guess is that you should also pass the user name and password of the sql user configured to access your database.

    Cheers,

    Michael.

  • Lars 66 posts 136 karma points
    Jan 07, 2011 @ 21:13
    Lars
    0

    YES. Someone answered me.

    But what do you mean precisely, I would like to understand it all.

    Say that the IP of the server is 123.45.678.90 and the login is "Mylogin" and the password is "Mypass".

    "Data Source=123.45.678.90; ......" instead of (local)?

    Thank you so far, Michael

    Regards, Lars

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Jan 08, 2011 @ 14:40
    Michael Latouche
    0

    Hi Lars,

    In that case, if your data is stored in the database "MyDatabase", you should have the following entry in your web.config file in order for Umbraco to access the data:

      <appSettings>
        <add key="umbracoDbDSN" value="server=123.45.678.90;database=MyDatabase;user id=Mylogin;password=Mypass" />
        ...
       </appSettings>

    If you then have custom tables you want to use from your custom controls, you can probably create your connections by accessing that same key via the default .Net ConfigurationManager object, or create a separate connection string entry in the web.config. Just put the following code somewhere under the main <configuration> node of your web.config file:

      <connectionStrings>
        <add name="MyCustomConnectionString" connectionString="Data Source=123.45.678.90;Initial Catalog=MyDatabase;password=Mypass;Persist Security Info=True;User ID=Mylogin;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
     </connectionStrings>

    You can then get the connection string in your code by doing the following (or something similar to):

    var myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyCustomConnectionString"].ConnectionString)

    I personnally create a separate connection string entry, so that I clearly separate what is Umbraco related and custom development related. Plus, this allows you to very easily put your custom tables on a separate database later on if needed, without needing to change any of your code regarding database connectivity.

    Cheers,

    Michael.

  • Lars 66 posts 136 karma points
    Jan 09, 2011 @ 10:55
    Lars
    0

    Hello Michael.

    I prefer clearly a seperate string. The strange thing is that I tried with a string

    string myString = "Data Source=www.myweb.com;Initial Catalog=my_catalog;Persist Security Info=True;User ID=myUser;Password=myPassword";

    It works perfectly when I access the database from Visual Web Developer or SQL Server Management Studio but it doesn't work inside the Umbraco installation.

    Anyway thank you once again a lot for your answer, you probally saved my day. I look forward to try it tomorrow!

    Regards

    Lars

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Jan 10, 2011 @ 16:53
    Michael Latouche
    0

    Hello Lars,

    Strange indeed. Did you specify the data provider explicitely? How did you create your actual connection using that "myString" value? Maybe Visual Web Dev and SQL Server Mgt Studio take the SQL provider "by default", unlike the place you installed your Umbraco site (although this seems unlikely to me)??

    Anyway, I hope the web.config solution will indeed solve your problem. Let me know :-)

    Cheers,

    Michael.

Please Sign in or register to post replies

Write your reply to:

Draft