Copied to clipboard

Flag this post as spam?

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


  • adrianfriend 67 posts 68 karma points
    Dec 15, 2011 @ 19:22
    adrianfriend
    0

    .NET Controls in Razor

    Hi all,

    I need to put a search box & button within a Razor .cshtml file. I can't really get round it as the design calls for a search slap bang in the middle of some linked navigation.

    Is it possible to add asp:TextBox & asp:ImageButton to Razor files? And can you create events to redirect to search page with querystring.

    Or is there a simpler way? :)

    Adrian

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 15, 2011 @ 21:13
  • Adi 17 posts 36 karma points
    Dec 16, 2011 @ 15:23
    Adi
    0

    I created a user control like this and works fine.

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SearchForm.ascx.cs"
        Inherits="TPControls.usercontrols.SearchForm" %>
    <div id="formsearch">
        <span>
            <input type="text" name="s" id="s" placeholder="Search" class="editbox_search" /></span>
        <input type="image" class="button_search" src="/css/images/search_btn.gif" onclick="return searchForm();" />
    </div>
    <script type="text/javascript">
        function searchForm() {
            var s = document.getElementById("s").value;
            if (s == "") {
                alert('please enter text to search');
                return;
            }
            var strUrl = "http://" + document.domain + "/Search.aspx?s=" + s;
            window.location = strUrl;
            return false;
        }
    </script>

Please Sign in or register to post replies

Write your reply to:

Draft