Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Need to call current webpage Page_Load() method in javascript function without clearing values in the pages. Currently i am using window.location.reload(); but it clears the values in my current page.

XML
function AssignPatIDtoHiddenField(PatID) {
      
      document.getElementsByName('HiddenField1')[0].value = PatID;     
 
      window.location.reload();     
 
  }


Here i am assigning value to hiddenfield but once the page is reload the hiddenfield value is becoming empty. i tried using session variable same problem. Pls help me
Posted
Updated 5-Feb-14 23:19pm
v2

Try like this

Create a hidden button in the Page and on the click event on the server, call the page load.

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="jquery-1.10.2.js" type="text/javascript"></script>
    <script type="text/javascript">

        function ReloadPatientDemo(PatID) {

            document.getElementsByName('HiddenField1')[0].value = PatID;
            document.getElementById('btnHidden').click();

        }


    </script>
</head>
<body>
    <form id="frm" runat="server">
     <asp:Button ID="btnHidden" runat="server" Style="visibility: hidden" OnClick="btnHidden_Click" />
    </form>
</body>
</html>




C#
protected void Page_Load(object sender, EventArgs e)
       {
// do something....
       }

       protected void btnHidden_Click_Click(object sender, EventArgs e)
       {
           Page_Load(null, null);
       }
 
Share this answer
 
Comments
Member 8653959 6-Feb-14 5:39am    
Thanks for ur answer.
Now i am using _doPostBack

__doPostBack("Registration", "Page_Load");
Karthik_Mahalingam 6-Feb-14 5:56am    
ya optional way .. good.
Siva Hyderabad 6-Feb-14 6:16am    
+5
Karthik_Mahalingam 6-Feb-14 8:02am    
Thanks Siva:)
Calling reload will just reload the page. What you want is to do a Postback using JavaScript. There are plenty of examples on the web available for that, here are a few

Generating Client-Side Script for Postback[^]
ASP.NET postback with JavaScript[^]
How postback works in ASP.NET[^]
Usage of doPostBack in a Real Environment[^]

There are plenty of more examples to find in Google.
 
Share this answer
 
Comments
Member 8653959 6-Feb-14 5:39am    
Thanks for ur answer.
Now i am using _doPostBack

__doPostBack("Registration", "Page_Load");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900