Click here to Skip to main content
15,889,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. Can someone help me with codes that can open a new page on button click event.
However, the twist is that a function has to be executed first before redirecting to a different page and the current page to reload.

Here is what I tried:

Page Name: ~/Application/BenefitsRequest.aspx

ASP.NET
<asp:Button ID="btnSubmit" runat="server" Text="Submit & Print" Width="150px" OnClick="btnSubmit_Click" OnClientClick="if(confirm('Do you want to submit and print the reimbursement?')){this.style.background='#98201a url(../Images/HeaderFooterMainTemplate/loader.gif)'; this.value = 'Processing...';}else{return false;}" />


C#
protected void btnSubmit_Click(object sender, EventArgs e)
{
   string toDate="";
   string fromDate="";
   fromDate = "1/1/1900";
   toDate = "1/1/1900";
        
   try
   {
      Label lblLoggedAs = (Label)Master.FindControl("lblLoggedAs");
      AddReimbursement("3", drpReimburseType.SelectedValue.ToString());//THIS IS A FUNCTION
      DeleteAllTrxRecord(); //THIS IS A FUNCTION
      string url = "~/Printing/ReimbursePrint.aspx?pg=3";
      Page.ClientScript.RegisterStartupScript(this.GetType(), "openlink", "window.open(url);", true);  
      Response.Redirect("~/Application/BenefitsRequest.aspx");
    }
    catch (Exception ex)
    {
      ClientScript.RegisterStartupScript(typeof(Page), "Error", "<script type='text/javascript'>alert('"+ex.Message+"')</script>");
     }
}


What I have tried:

i TRIED THE ABOVE CODE, please comment if u have questions
Posted
Updated 3-May-16 23:49pm
Comments
Karthik_Mahalingam 4-May-16 4:06am    
rediret to BenefitsRequest.aspx and
open ReimbursePrint.aspx in new tab ?
bjay tiamsic 4-May-16 21:40pm    
Exactly. Is that possible?

try this
C#
string url = "~/Printing/ReimbursePrint.aspx?pg=3";
          Page.ClientScript.RegisterStartupScript(this.GetType(), "openlink", "window.open('" + url + "');   window.location.href = '~/Application/BenefitsRequest.aspx'", true);
          Response.Redirect("~/Application/BenefitsRequest.aspx");
 
Share this answer
 
Comments
bjay tiamsic 4-May-16 22:09pm    
This worked but have to allow popup. If user is not knowledgeable about that, this approach is not acceptable, are there any other ways?
Karthik_Mahalingam 4-May-16 22:13pm    
Can you provide more details so that I can come up with other solution.
but I have given answer as per your question
bjay tiamsic 4-May-16 23:51pm    
your solution worked but the popup blocker has to be turned off. I will be needing a solution that does not need to consider browser issues because I know popup blocker cannot be bypassed.
Karthik_Mahalingam 4-May-16 23:59pm    
that is browser functionality and its not in the control of code, it is controlled by browser user.
Try some alternative for the popup using div modal popup or someother.
Use your own form id for "form1", and before you say it "doesn't work" check for pop-up blockers etc.

ASP.NET
<asp:Button ID="btnSubmit" runat="server" Text="Submit & Print" Width="150px" OnClick="btnSubmit_Click" OnClientClick="if(confirm('Do you want to submit and print the reimbursement?')){document.getElementById('form1').target='_blank'; window.setTimeout(function(){document.getElementById('form1').target=''},1000); this.style.background='#98201a url(../Images/HeaderFooterMainTemplate/loader.gif)'; this.value = 'Processing...';}else{return false;}" />
 
Share this answer
 

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