How to postback the Asp.net page with Javascript or Jquery

Asked

Viewed 1,982 times

2

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 if I click again on the tag in this case to close, give a post on the dropdownlist and gridview components going back to the state of choice. It is possible to do this ? My code is like this today:

<script type="text/javascript">

        $(document).ready(function () {
            $('.a').click(function () {
                $("#pnlSalas").toggle();
            });
        });
</script>
  • For lack of time I could not give an answer to your previous question, but follows a link that contains the answer to your question. http://stackoverflow.com/questions/3863927/lost-focus-method-for-asp-net-textbox

  • I’ll try here, thanks @Marciano.Andrade

  • @Andreeh That’s the same question you asked days ago, I think you better delete the other and keep this.

  • Beauty @Marconi. I still can’t solve ..

  • @Andreeh has to be with the toogle function? I was thinking of doing the code bind.

  • Seguinte Andree, based on the answer there to use the method __doPostBack('','') in javascript, where this method is from the ajax of .net. Calling this method, a post back is executed and the method parameters are sent in the page_load event of your page.

  • in the page load you need to do the treatment of this postback, and that’s what the reply is referring to. That’s what you tried to do?

  • That’s right, and it didn’t work ..

Show 3 more comments

1 answer

-1

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

If you want to give a post, you need to enable this "tag" control with a runat="server", thus, with a _doPostBack in the attribute, you can identify the event in the pageLoad of your page, and so do what you want with your controls (dropdown and grid) which are controls "server," all right? This would be the quick solution, then identifying the click on 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 from the controller you enabled in 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, no post, you have to create a javascript function, find the elements (can be with jquery keys) and assign the property val() pro dropdown.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.