Click here to Skip to main content
15,077,377 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I am using the script below but it s not redirecting the page.

C#
string rdpConnect = "function btnShowID_onclick(){" +
            "if(document.getElementById('MainContent_ctl00_txtBeginDateID').value!='' && document.getElementById('MainContent_ctl00_txtEndDateID').value!='' && document.getElementById('MainContent_ctl00_ddlAuditorsID').value!='' )" +
            "{" +
                    //"alert($('#ContentPlaceHolder1_ucSample_txtName').val());" +
                "$.ajax({type: 'POST'," +
                "url: '~/WebService.asmx/Navigatetopage'," +
                "data:  '{zip:jhg}'," +
                "contentType: 'application/json; charset=utf-8'," +
                "dataType: 'json'," +
                "success: function(msg) {" +
                    "if(msg.d=='True'){" +
                            //"window.location.href='~/ReportPage/ReportViewerForAll.aspx?&ReportName=" + _reportName + "';" +
                            "window.location.href='Default.aspx'"+
                        "}" +
                    "}" +
                 "});" +
              "}" +

            "else" +
            "{" +
                "alert('Please Enter The Required Field(s)');" +
                "return false;" +
            "}" +
            "}";


                rdpFunctions.InnerHtml = rdpConnect;
                this.Controls.Add(rdpFunctions);
                flag = false;
            }



Any idea or help is higly appreciated.
Thanks in advance

Shafik
Posted
Updated 8-Jan-13 5:20am
v2

1 solution

What if the condition is true, but the ajax call isn't a succes? This would not show. Try to add code for the error situation, like this:
$.ajax({
    url: ...,
    data: ...,
    dataType: 'json',
    type: 'POST',
    timeout: 10000,
    success: function(json){
      //some code
    },
    error: function(jqXHR, textStatus, errorThrown){
      //some code
    }
 });


Good luck!
   
Comments
[no name] 8-Jan-13 12:39pm
   
Thanks for your Anser 1000 times. Now my code lool loke below:

function btnShowID_onclick()
{
if(document.getElementById('MainContent_ctl00_txtBeginDateID').value!='' && document.getElementById('MainContent_ctl00_txtEndDateID').value!='' && document.getElementById('MainContent_ctl00_ddlAuditorsID').value!='')
{
$.ajax({
url: '~/WebService.asmx/Navigatetopage',
data: '{zip:jhg}',
dataType: 'json',
type: 'POST',
timeout: 10000,
success: function(json)
{
window.location.href='Default.aspx';
return true;
},
error: function(jqXHR, textStatus, errorThrown)
{
alert('Please Enter The Required Field(s)');
return false;
}
});
}
}

But stil i am getting only error message.its not going to default.aspx
Can you plz tell me where i suppose to change my code.

Thanks
Shafik
E.F. Nijboer 14-Jan-13 8:39am
   
Have you looked at the parameters of the error function? They should give you more info about what is going on.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



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