Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing value to code behind with jQuery

Tags:

jquery

c#

asp.net

Need to pass a value from web page to codehind from a hyperlink with a parameter like e.g. page.aspx?id=1. I want to use jQuery if appropriate

How can I pass this value to the code behind without exposing as a querystring in the browser?

like image 506
user1934500 Avatar asked Apr 22 '26 12:04

user1934500


2 Answers

One way to do it is to use an ASP.NET hidden field.

<asp:HiddenField id="hdnWhatever" runat="server" value="blah" />

This field can then be manipulated with javascript or jquery and can also be easily used in your codebehind.

like image 87
Jagd Avatar answered Apr 25 '26 01:04

Jagd


Try submitting form as jSON .. Sample -> replace [#form-request] with your form and [/index.php?option=com_seomozapi&task=request.save] with the file action/destination .. return false will keep the focus on current page (no server side refresh)

getScript('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', function() {
    js = jQuery.noConflict();
    js(document).ready(function() {
        js('#form-request').submit(function(event) {

            console.log('test 1');

            $.post('/index.php?option=com_seomozapi&task=request.save'); ?>', $('#form-request').serialize(), function (data, textStatus) {
                //Do something here
            });
            console.log('test 3');
            return false;
            console.log('test 4');
        });
    });
});
like image 45
Michael Lucy Avatar answered Apr 25 '26 00:04

Michael Lucy