0

I wanna change or add custom attributes in client side by jquery and check them in server side by c#

(for example add a custom attributed named "Loaded=1" to an image HTML element when the image is loaded successfully and in server side I access to this attribute through Image control Attributes Collection)

Is it possible ??

Thanks for your feedbacks

Reza.Sorouri
  • 81
  • 1
  • 7

4 Answers4

2

I think you have a few Page Lifecycle aspects mixed up, the attributes that you set on client side never end up on server side, unless you post them to the server. I think you should consider adding hidden fields to forms via jQuery so that when the form is posted the values arrive at the server. Then server side you'd need to interpret the posted values and turn them into attributes on the correct Image objects.

Consider something like this:

Create the following element with jQuery:

<input type="hidden" id="Image23_Loaded" name="Image23_Loaded" value="1" />

Post this to server and parse it so you know which Image object should get the Loaded attribute.

Find the Image object and add the attribute server side.

Bazzz
  • 26,427
  • 12
  • 52
  • 69
1

You can also use asp HiddenField control. set it's value on client side and you can access it on server side. If your HiddenField id is "hdnImage1" you can set it's value on jquery like $('#<%= hdnImage1.ClientID %>').val('1');. Hope this help.

0

You may also post a JSON result object to the server using AJAX and de-serialize it to an .net object.

take a look at: https://stackoverflow.com/a/2246724/952310

Community
  • 1
  • 1
Yair Nevet
  • 12,725
  • 14
  • 66
  • 108
0

you can't do that. Once the page has been transferred, the server side cannot access the page

You can however, transfer data using $.post(url,data, callback) data can be obtained from a form or serialized array

SoWhat
  • 5,564
  • 2
  • 28
  • 59