How do I perform a conditional call of a javascript function from c# code behind

I have a .ascx control which includes some form elements including a radiobutton group containing 3 radiobuttons. I have linkbuttons that performs updates / inserts in the parent aspx page. When I click on either update or insert I want to save the data then check the selected value of the radiobutton group and if that value = 1 call a javascript function that opens another aspx page in the current window.

Please find the relevant code attached. In it you can see, in terms of the sequence of events where I need to call the JS code.

kind regards

Verdy
HTML
<tr>
  <td>
    <asp:RadioButton ID="rbBook" GroupName="RC" Text="Confirm booking" runat="server"  />
  </td>
  <td>
     <asp:RadioButton ID="rbCancel" GroupName="RC" Text="Cancel waitlst" onclick="EnterAppointment();"
              runat="server"  />
  </td>
  <td>
     <asp:RadioButton ID="rbNothing" GroupName="RC" Text="No action" runat="server" onclick="EnterAppointment();"/>
   </td>
</tr>

JS FUNCTION
<script language="javascript" type="text/javascript">
  function openPatient(patid)
  {
     this.location.href = "home.aspx?a=openPatient&pid=" + patid;
   }
</script>    


CODE BEHIND
protected void rgWaitList_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
  WaitListControl ctrl = (WaitListControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
  EpiData.data.pat_wait_list data = ctrl.Getdata();
  Savedata(data);
  if (data.confirmed = 1)
   {
     //	Call javascript function;
   }
  else
   {
                InitPage();
   }
}

Open in new window

verdanteAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

masterpassCommented:
Try this


protected void rgWaitList_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
  WaitListControl ctrl = (WaitListControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
  EpiData.data.pat_wait_list data = ctrl.Getdata();
  Savedata(data);
  if (data.confirmed = 1)
   {
     Page.ClientScript.RegisterStartupScript(this.GetType(), "open", "openPatient('"+patidhere+"')", true);// pass the required patid 
   }
  else
   {
                InitPage();
   }
}

Open in new window

0
verdanteAuthor Commented:
Thanks mp
I am getting a JS error when I debug with firebug as follows:
missing ; before statement
openPatient('5831')Sys.Application.initialize();\n
Not sure of what the Sys.Application.initialize statement is so my own self help was pretty useless!
Any suggestions?
thx kindly
Verdy
0
masterpassCommented:
just change this alone .. i think a semi-colon was missing after the function call



Page.ClientScript.RegisterStartupScript(this.GetType(), "open", "openPatient('5831');", true);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
verdanteAuthor Commented:
Thx so much masterpass, worked a treat. And a very handy little piece of code to know!!!

cheers

Verdy
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.