adic26
adic26

Reputation: 1137

passing data from javascript to asp.net on click event

I have an asp.net gridview control:

<asp:GridView runat="server" ID="grdRequestSearch" AutoGenerateColumns="true" CssClass="myGrid"></asp:GridView>

Which executes this method:

 Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim searchFields As New DataTable("SearchFields")
        searchFields.Columns.Add("TableType", GetType(String))
        searchFields.Columns.Add("ID", GetType(Int32))
        searchFields.Columns.Add("SearchTerm", GetType(String))
        searchFields.Columns.Add("ColumnName", GetType(String))

        For Each field As ListItem In 'javascript values
            Dim dr As DataRow = searchFields.NewRow
            Dim splitField As String() = field.Text.Split(":"c)

            dr("TableType") = 'need value from javascript
            dr("ID") = 'need value from javascript
            dr("SearchTerm") = 'need value from javascript
            dr("ColumnName") = 'need value from javascript

            searchFields.Rows.Add(dr)
        Next

        grdRequestSearch.DataSource = ReportManager.Search(ddlRequestType.SelectedItem.Value, searchFields)
        grdRequestSearch.DataBind()
    End Sub

All of this data gets binded in a grid data view.

What I need to do is get values from a javascript function which I need to parse using 'javascript values in javascript Returned function.

Can anyone help me on how to pass data from javascript function to asp.net control?

Upvotes: 0

Views: 814

Answers (1)

PPC-Coder
PPC-Coder

Reputation: 3632

You're kind of going against the grain of ASP.Net WebForms. Instead of having the values in a javascript variable you should use something like ASP.Net TextBox controls which will be accessible when the click handler gets invoked on the server.

However, if you must do things in Javascript, you'll need to use something like a hidden INPUT field that you populate with your variables and will get POSTed back with the request. Once back on the server you need to extract those form values.

Upvotes: 1

Related Questions