How to give a postback in the asp.net page with Javascript or Jquery

3

Today I have a function that calls the toggle method when I click on the tag it displays the panel in ASP.NET containing a dropdownlist and a gridview. I need every time I click the tag again in this case to close, give a post on the dropdownlist and gridview components and return them to the state of choice. Is it possible to do that ? My code looks like this today:

<script type="text/javascript">

        $(document).ready(function () {
            $('.a').click(function () {
                $("#pnlSalas").toggle();
            });
        });
</script>
    
asked by anonymous 02.06.2015 / 19:22

1 answer

-1

So the first thing that has to be clear is the following, you want it when the guy clicks the "tag" it gives a post on the page or do you want to do it with javascript?

If you want to give a post, you need to enable this "tag" control with a runat="server", so with a _doPostBack in the attribute, you can identify the event in your pageLoad page, whatever you want with your controls (dropdown and grid) that are "server" controls, right? This would be the quick solution, hence identifying the click on the pageLoad, just change the values. Dropdown.SelectedValue="0" and DataGrid.DataSource = New DataTable (0), for example.

An example of how to get the _doPostBack event of the control that you enabled in the page_Load.

 Dim eventTarget As String = IIf(Me.Request("__EVENTTARGET") = Nothing, String.Empty, Me.Request("__EVENTTARGET"))

    'Evento de Pesquisa do botão ENCONTRAR
    If eventTarget.Equals("ValorArgumento") Then
        MetodoAção()
    End If

In Html you will set the following:

 <button onclick="__doPostBack('ValorArgumento', '')" id="idBotao" type="button"></button>

Now, if you want to do this with javascript, without post, you have to create a javascript function, find the elements (can be with jquery keys), and assign the val () pro dropdown property.

    
01.09.2015 / 21:18