Reputation: 13582
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
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
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
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
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