0

I'm new in ASP and I am stucked with my ascx control. I have a control Upload.ascx with the following init code

 <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Uploader.ascx.cs" Inherits="Uploader" %>
 <script type="text/javascript" > 
 $(function ()
 {
    var guid = GUID();//GUID() - js function which 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 control declaration looks like the following

 <my:Uploader ID="upload" OuterId="upload" ClientIDMode="Static" runat="server" /> 

In my JS I can access the attribute $('#upload').attr('guid') and it gives correct value. But when I submit the form, my upload.Attributes["guid"] becomes null in codebehind. How can I access it and what am I doing wrong?

1 Answer 1

2

You cannot do it like this:

There are two ways:

Pass the GUID from the server and store in some literal and access the literal using JQuery etc

OR

Create an server side hidden field and assign the value.

<asp:HiddenField runat="server" ID="hidden" />

$('[id$=hidden]').val(guid);

On submit access the hidden field

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

1 Comment

Oh, thanks man, it solved my problem )) Is there any way to access the hidden control by ID, or I have to check my Request.Params to get the guid value?

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.