0

I am calling asp.net button click event through jquery.

$('[id$=btnSaveAsp]').click();

I am sending html data into asp.net hidden field. It is working fine with small amount of data but it is not firing with large amount of data. What should I do???

2
  • Please look at how to target asp.net controls using jquery. stackoverflow.com/a/20227176/489512 Commented Apr 22, 2014 at 15:49
  • This is a damn common error =) Commented Apr 22, 2014 at 15:51

2 Answers 2

1

You have to change your code to

$('#'+'<%= aspBtn.ClientID %>').click();

As I see you select you dom element using jquery and it's id. In order to accomplish this you should use the # inside your selector. Also you haven't to use =id$ = inside you selector.

Generally, when you want to select an element using jquery and the id of the element, you have to follow the following pattern:

$('#id')

where id is the id of the element you want to select.

For further documentation on this, please look here.

Sign up to request clarification or add additional context in comments.

5 Comments

what is the difference using "#"
There isn't any difference. Just when you have to select elements by id and using jquery you have to follow this way. I will post a couple of links in order to make it more clear, if it is not.
my problem is that it is not firing with large amount of data
@RizwanQureshi if that's your only code, it shouldn't fire even with few data. The reason why I am telling this is that you don't attach the event to the element you want - to the button -, because you have not selected it correctly. It's not a matter of the size of data you have. If that's not clear I could provide you with a link to fiddle to see what I mean. Please just let me know. Thanks
Please try to use, what I have posted, $('#'+'<%= aspBtn.ClientID %>').click(); . This will work. If it doesn't, please just let me know -in that case somewhere else should be the problem. But in any case the way you have selected the element is not correct.
1

It is not the problem of click event. It is actually problem of http runtime in asp.net web config file Please add this tags in web.config to resolve this issue.

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="40960" requestValidationMode="2.0"/>
        <pages validateRequest="false"></pages>
    </system.web>
</configuration>

2 Comments

Ok, your request is too big and you have to make this change to your web.config. My questions still remains the same. does the click event works, if you make this change? I mean does this piece of code $('<%=id$ = aspBtn.ClientID %>').click(); works? I still believe it is not.
Sory chris, I wrote my code by minor mistake. my click code is $('[id$=btnSaveAsp]').click(); and it is working fine with this changes in web.config

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.