Dave Burke : Freelance .NET Web Developer specializing in Online Communities

CSBlogs : Setfocus() on search text field

CSBlogs searching is great.  Almost as good as the dotLucene code I grabbed from dotText 0.96 and added to my 0.95 build.  I might have to tweak it a bit, but I haven't tested it much yet.

I thought I'd add a little extra sweetness to CSBlog searching and add a Setfocus() to the search text field when the page loads.  As a result (in addition to CS search button DefaultButton behavior), anyone who loads a page can enter a search, press [Enter], retrieve their results, and never have to touch a mouse.

I added to Setfocus() method to SingleWeblogSearch.cs in CommunityServer.Blogs.Controls and that was pretty much that.


protected void SetFocus(Control controlToFocus)
{
 System.Text.StringBuilder sb = new System.Text.StringBuilder();
 string scid;
 scid = controlToFocus.ClientID;
 sb.Append("<script language='javascript'>");
 sb.Append("document.getElementById('" + scid + "').focus();");
 sb.Append("</script>");
 Page.RegisterStartupScript("focus",sb.ToString());
}

Comments (4) | Post RSS RSS comment feed

Posted on 3/22/2005 4:19:00 PM by Dave Burke
Categories: Community Server
Tags: no tags for this post

Related posts

Comments (4) -

3/31/2005 7:18:16 PM Permalink

I  tried to add this, and I got an error;
Community Server\blogs\Controls\SingleWeblogSearch.cs(51): The type or namespace name 'Control' could not be found (are you missing a using directive or an assembly reference?)

I added the code just below here;
private void SearchButton_Click(object sender, EventArgs e)
(
....
)

protected void SetFocus(Control controlToFocus)
(
...
)


Did I miss something?

v g blog AT the gill family DOT us

vern |

3/31/2005 7:21:57 PM Permalink

Vern, Control is in the System.Web.UI namespace.  Make sure at the top of your class you have a "using System.Web.UI" statement.  That's probably the problem.  If not, let me know.

daveburke |

3/31/2005 8:50:20 PM Permalink

You are so the man!

Thanks!

Lookin forward to more mods!

vern |

3/31/2005 8:52:17 PM Permalink

Always happy to help promote the Gill Family blogging effort!  Glad that was the problem.

Testguy Jones |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke