JQuery and LinkButtons, or regular buttons and CSS

I have a small control on my main page. In the login control, I use the LinkButton button to submit, because I like the way it looks.

However, I also use jQuery to capture when I press the 'enter' key in any of the input control text boxes. It is hard to trigger the click event of a link button with jQuery in every browser. I even tried hardcoding __doPostBack, but the ID of LinkButton is just a little different from that in the built-in attribute href = "__ doPostBack" on the control. It does not respond to .trigger (), click (), etc.

On the other hand, a regular Button control works just fine with jQuery click (). But I'm not a big fan of buttons, and my CSS skills are limited. Is there an easy way to create a regular ASP.NET control to look like a link? Or is there an easy way to get LinkButton to behave with jQuery? I will choose which method takes less effort. :)

Thanks in advance.

+3
source share
2 answers

You can get the exact JavaScript that LinkButton runs using the ClientScriptManager :

string postbackFunction = this.Page.ScriptManager.GetPostBackEventReference(myLinkButton, "");

string jQueryBlock = @"$('#loginbox').keypress(function(e){
    if(e.which == 13) {" + postbackFunction + ";}});

//print the jQueryBlock to the page

It will output a JS function call that looks something like this:

__doPostBack('linkButtonID','', 0);
+2
source

, <input type="submit"> <button> CSS:

input.button,
button {   
    margin: 0;
    padding: 0;   

    color: blue;
    background: none;
    border: 0;   

    cursor: pointer;
}

, .

, , , -. . , , .

0

Source: https://habr.com/ru/post/1756836/


All Articles