3

May be I am missing something important in order to implement CustomControl properly as per requirement or having a lack of knowledge. Actually I have Created CustomControl (.dll)for searching purpose having 3 Dropdown boxes(populating from database), 1 textbox and search button, after choosing appropriate filter criteria user clicks on Search button and simple gridview appears. My problem is I dont want to fill dropdown boxes in CustomControl on every post back(fired from page).

2
  • 2
    Do you check the IsPostback property in the control on Page_Load? Commented Jun 28, 2014 at 8:48
  • I am not getting IsPostback property, I implemented override void OnInit(EventArgs e) & override void CreateChildControls() Commented Jun 28, 2014 at 8:53

1 Answer 1

2

When you are in a place that can not spot the Page you can use this global parameter:

System.Web.HttpContext.Current

Now from that you can get the Page if its available,

Page page = HttpContext.Current.Handler as Page;

if (page != null && page.IsPostBack)
{

}

or you can get the Form and the post back values using

System.Web.HttpContext.Current.Request.Form

and check if the Form have values, then is probably post back.

Just a note, always check if the System.Web.HttpContext.Current is not null before using it, because if you call it from a thread and there is no page available, then is null.

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

2 Comments

Hi Aristos! thanks for your answer, now I am getting PostBack, but my problem was as it is, when second time CreateChildControls() calls, if doesn't load values in dropdown boxes, it gets lost.
@VishwanathMishra Maybe then the viewstate for this control, when they use it, is disabled. (or you did not save on viewstate this controls)

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.