Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Instead of trying to get the value from the server control in the static page method, have jQuery get the selected value and send it to your page method, like this:</p> <pre><code>$(document).ready(function() { var selectedMake = $('#&lt;%= MAKE.ClientID %&gt;' option:selected").text(); var args = { theMake : selectedMake } $.ajax({ type: "POST", url: "YourPageName.aspx/Select_Search", data: JSON.stringify(args), contentType: "application/json; charset=utf-8", dataType: "json", success: function(result) { // Do something with result here } }); }); </code></pre> <p>This requires a change to the static web method, in order to allow it to accept a parameter now, like this:</p> <pre><code>'Static or shared Web Method' &lt;WebMethod()&gt; _ Public Shared Function Select_Search(theMake As String) As string Dim dtst As New DataTable() Dim List As New dsStockTableAdapters.newSTOCK_LISTTableAdapter() dtst = List.GetData(theMake) Return dtst End Function </code></pre> <p>Now you do not have to attempt to find the value of the server control in a static method, because it was sent to the static method as a parameter.</p> <blockquote> <p>Notes:</p> <ul> <li>The JSON.stringify function is part of the [JSON.js library]>>(<a href="https://github.com/douglascrockford/JSON-js" rel="nofollow">https://github.com/douglascrockford/JSON-js</a>)</li> <li>The example above makes extensive use of jQuery, make sure you have a reference in your page or master page, if you are using them, to the jQuery script file</li> <li>I am not sure what you are actually doing in your page method, because it is declared as returning a String, but it appears to trying to return a List, along with an unused Catch block, I deleted the unused Catch and Finally blocks and had it return the dtst object, feel free to correct this as needed.</li> </ul> </blockquote> <hr> <p>UPDATE:</p> <p>The only option you have server-side to allow access to the value in the <code>Static</code> web method is to use <code>Session</code> cache to store the drop down's selected value when it is changed via the drop down's <code>SelectedIndexChanged</code> event, like this:</p> <pre><code>Sub Index_Changed(sender As Object, e As EventArgs) Session("SelectedMakeValue") = ddlMake.SelectedItem.Value End Sub </code></pre> <p>Now you must give the <code>Static</code> web method access to the <code>Session</code> cache, like this:</p> <pre><code>'Static or shared Web Method' &lt;WebMethod(EnableSession := True)&gt; _ Public Shared Function Select_Search() As string Dim dtst As New DataTable() Dim List As New dsStockTableAdapters.newSTOCK_LISTTableAdapter() Dim theMake As String = HttpContext.Current.Session("SelectedMakeValue").ToString() dtst = List.GetData() Return dtst End Function </code></pre> <blockquote> <p>Note: You must use the fully qualified name for the <code>Session</code> object, which is <code>HttpContext.Current.Session</code>; otherwise you will get errors.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload