Saeid
Saeid

Reputation: 13582

Retrieve Html Control Value in other Classes

I have an element like this in Default.aspx :

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

And now I need to retrieve this element value in another class like the following:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Sample001 {
    public class SlaveValue {
        public void RetrieveValue() {
        }
    }
}

How can I do this?

Edit:

It's some complicated, I add value to element inside of jQuery Script and when the request of jQuery Ajax send I need this value in HttpHandler to response correctly.

Upvotes: 0

Views: 126

Answers (4)

Vasan
Vasan

Reputation: 375

After reading @Saeid saying "I actually do in httpHandler for handle jQuery Ajax request", you could just pass the hidden field as a query string (assuming its a get method) and access it in your handler using the httpcontext object, for e.g. context.Request.Params["HiddenValue"]. Hope this helps.

Upvotes: 0

DeveloperX
DeveloperX

Reputation: 4683

when do u want to do that?is it in postback? then you can pass the page to this class constructor so you can access to page controls via FindControl method

Pageisntance.FindControl('controlid')

Upvotes: 0

Icarus
Icarus

Reputation: 63956

You can't. Store it somewhere else. I don't recommend putting on session since this would break your separation of concerns but perhaps your class is meant to be used only inside this web app. If that's the case, Session is probably the best candidate.

You could do

 HttpContext.Current.Session["key"] = ...

Upvotes: 1

Heinzi
Heinzi

Reputation: 172270

Pass a reference of your Page instance to the class. Then you should be able to access the value as myPageReference.hfID.Value.

Upvotes: 0

Related Questions