locked
SanitizeUserInput in VB RRS feed

  • Question

  • User704152319 posted

    Hi,


    I have found Google Site Search Code in C# as below,  I had tried to convert into VB code but there are 2 problems encountered as underlined:


    Problem 1: Name 'SanitizeUserInput' is not declared. What it supposed to be in VB code

    C# Code 1

    protected void _btnSearch_Click (Object sender, EventArgs e)
    {
        if (!IsValid)
            return;
        Response.Redirect (
            String.Format(
                "Default.aspx?q={0}&cx={1}&cof={2}",
                HttpUtility.UrlEncode (SanitizeUserInput (q.Text.Trim ())),
                HttpUtility.UrlEncode (cx.Value),
                HttpUtility.UrlEncode (cof.Value)
                ),
            false
            );
        Context.ApplicationInstance.CompleteRequest ();
    }


    protected void _btnSearch_Click (Object sender, EventArgs e)

    {

        if (!IsValid)

            return;

        Response.Redirect (

            String.Format(

                "Default.aspx?q={0}&cx={1}&cof={2}",

                HttpUtility.UrlEncode (SanitizeUserInput (q.Text.Trim ())),

                HttpUtility.UrlEncode (cx.Value),

                HttpUtility.UrlEncode (cof.Value)

                ),

            false

            );

        Context.ApplicationInstance.CompleteRequest ();

    }


    VB Code 1

     Protected Sub _btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles _btnSearch.Click

            If Not IsValid Then

                Exit Sub

            End If

    Response.Redirect([String].Format("Default.aspx?q={0}&cx={1}&cof={2}", HttpUtility.UrlEncode(SanitizeUserInput(q.Text.Trim())), HttpUtility.UrlEncode(cx.Value), HttpUtility.UrlEncode(cof.Value)), False)


            Context.ApplicationInstance.CompleteRequest()


        End Sub


    Problem 2: Name 'q' & name 'SanitizeUserInput' is note declared

    C# 

    Code 2

    protected void Page_Load (Object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            String query = Request.QueryString["q"];

            if (!String.IsNullOrEmpty (query))

            {

                q.Text = SanitizeUserInput (HttpUtility.UrlDecode (query.Trim ()));

            }

        }

    }


    VB Code 2

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If Not IsPostBack Then

                Dim query As [String] = Request.QueryString("q")

                If Not [String].IsNullOrEmpty(query) Then

                    q.Text = SanitizeUserInput(HttpUtility.UrlDecode(query.Trim()))

                End If

            End If

        End Sub


    Thanks alot!!!

    Friday, April 16, 2010 6:01 PM

Answers

  • User197322208 posted

    1. Sanitize user input is not a C# or VB function. So download the entire project and found

    2.

    q.Text =

    must be a control( like a textbox) in the aspx page that has the name q

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 17, 2010 2:18 AM

All replies

  • User197322208 posted

    1. Sanitize user input is not a C# or VB function. So download the entire project and found

    2.

    q.Text =

    must be a control( like a textbox) in the aspx page that has the name q

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 17, 2010 2:18 AM
  • User704152319 posted

    Thanks. I got it

    Monday, April 26, 2010 4:46 PM