Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I wanted to call a method declared in my code behind page, actually that method is used for refracing the data of datagrid in asp page, i used a c# as my code behind language.
this is the method....

C#
public void search()
{
    int id = Convert.ToInt32(txtSearch.Value.ToString());
    ds.Clear();
    ds = (DataSet)ser.getDataID("SP_SELECT_DATA_FROM_INFO", id);
    if (ds.Tables[0].Rows.Count > 0)
    {
        grdMyGrid.DataSource = ds;
        grdMyGrid.DataBind();
    }
    else
    {
        Response.Write("No Record Found");
    }
}



now i want to call that method using a jQuery or javascript with Ajax...

i will try this but it is not working
JavaScript
<script type="text/javascript">
        $(document).ready(function () {
            $("#ser").click(function () {
                if (confirm("Are you sure")) {
                    $.ajax({
                        type: "POST",
                        url: "GridDemo.aspx/search",
                        contentType: "application/json; charset=utf-8",
                        data: "{}",
                        dataType: "json",
                        success: function (msg) {
                            if (msg.d) {
                                alert("Sucess");
                            }
                        },
                        error: function () {
                            alert("Error try again");
                        }
                    });
                }
            });
        });        
        }
    </script>



please help me....
Posted

Create your method as static and use the WebMethod[^] attribute
 
Share this answer
 
Comments
Nilesh Patil Kolhapur 22-May-12 2:33am    
nice answer
JavaScript
<script type="text/javascript">
        function doajax() {
            $.ajax(
            {
                url: "GridDemo.aspx/search",
                data: "flag=1",
                success: function (msg) {
                            if (msg.d) {
                                alert("Sucess");
                            } 
            }); 
       }
    </script>


In the code behind

C#
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.QueryString["flag"] != null) search();
}

public void search()
{
    int id = Convert.ToInt32(txtSearch.Value.ToString());
    ds.Clear();
    ds = (DataSet)ser.getDataID("SP_SELECT_DATA_FROM_INFO", id);
    if (ds.Tables[0].Rows.Count > 0)
    {
        grdMyGrid.DataSource = ds;
        grdMyGrid.DataBind();
    }
    else
    {
        Response.Write("No Record Found");
    }
}


I hope I was able to solve your problem.

Watch my first article posted on codeproject and comment and vote:
http://www.codeproject.com/KB/HTML/speechinputapi.aspx
or http://blog.robinrizvi.info

Drop me a mail for any comments, suggestions or questions.
mail@robinrizvi.info
 
Share this answer
 
Comments
KIRANJAY 7-Jan-12 0:08am    
I want to use progressbar for sending multiple emails,everytime progressbar will be updated on email send count..pls help me for this...plsssssss
Thanks in adv.
Robin Rizvi 8-Jan-12 9:52am    
Kiranjay drop me a email at my mail id (see above for my mail id) and describe your problem fully,tell is it php/asp.net/winforms and your code segment for mailing. Send all that and you problem text in the mail.
I will surely try after getting all details and provide you with a working code if possible.
KIRANJAY 9-Jan-12 0:22am    
hello sir,
thanks for your reply.
Actually my problem is I want add progressbar in my application.
In that, I want to send multiple emails -On emails sending count my progress bar will be increased..pls help me for this.I am trying for so much days
Robin Rizvi 9-Jan-12 8:39am    
is it winforms? windows app?....Kiran please do continue the conversation in mail (mail@robinrizvi.info). i'll be quick to reply. thanks
Robin Rizvi 9-Jan-12 9:35am    
Kiran you can also send me your solution file(the whole project) as an attachment and I could write the code for you. That way I could see what and where you want to accomplish the task. That would be easy and clear for us both.

One more thing to add you can easily add a progressbar control and update its value after sending the mail, that would work just fine. You would be using smtp mail(probably gmail or yahoo's smtp server) for sending mail from your windows application.
try {
$.ajax({

url: '../Handlers/HotelResult.ashx',
type: 'GET',
data: {
method: 'Reservation',
args: { SessionID: SessionID, HotelID: HotelID, Room1ID: Room1ID, Room2ID: Room2ID, Room3ID: Room3ID }
},
success: function (data) {
document.getElementById('ctl00_ContentPlaceHolder1_hdnhtlreservation').value = data;
if (document.getElementById('ctl00_ContentPlaceHolder1_hdnhtlreservation').value == 'true') {
window.location = 'HotelPayment.aspx?SessionID=' + SessionID;
}
else {
//display end portion of loading
$j('#divResult').unblock();
//$("#divLoading").hide();

alert('Não há quartos disponíveis foram encontrados para os seus critérios de pesquisa...');
return false;
}
}
});
} catch (e) {
}
 
Share this answer
 
Comments
[no name] 22-May-12 7:32am    
Not even close to what the OP needs.
Hard coded ids, such as ctl00_ContentPlaceHolder1_hdnhtlreservation

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