Sunday, 15 January 2012

c# - accessing javascript dynamic attributes from codebehind -



c# - accessing javascript dynamic attributes from codebehind -

i'm new in asp , stucked ascx control. have command upload.ascx next init code

<%@ command language="c#" autoeventwireup="true" codefile="uploader.ascx.cs" inherits="uploader" %> <script type="text/javascript" > $(function () { var guid = guid();//guid() - js function generates guid $('#' + '<%= outerid %>').attr('guid', guid); } </script> <div class="buttonnohover" runat="server" id="current">upload</div>

and cs init code (part of it)

protected void page_load(object sender, eventargs e) { current.id = this.id; }

my command declaration looks next

<my:uploader id="upload" outerid="upload" clientidmode="static" runat="server" />

in js can access attribute $('#upload').attr('guid') , gives right value. when submit form, upload.attributes["guid"] becomes null in codebehind. how can access , doing wrong?

you cannot this:

there 2 ways:

pass guid server , store in literal , access literal using jquery etc

or

create server side hidden field , assign value.

<asp:hiddenfield runat="server" id="hidden" /> $('[id$=hidden]').val(guid);

on submit access hidden field

c# javascript webforms code-behind

No comments:

Post a Comment