1

I have one image button in the custom control like below.

     public string SearchTableName = string.Empty;
       public string SearchColumnName = string.Empty;
       public string SiteURL = string.Empty;
        ImageButton _imgbtn;
         protected override void OnInit(EventArgs e)
         {
           _imgbtn = new ImageButton();
           _imgbtn.ImageUrl = ImageURL;
           _imgbtn.OnClientClick = "ShowSearchBox('" + SiteURL +"/_layouts/CustomSearch/SearchPage/Searchpage.aspx?table_name=" + SearchTableName + " &column_name=" + SearchColumnName + "')";
         }

On Clicking of the image button I want to migrate to the another window which is a popup. For this I written a javascript function. I am setting the SearchTableName and SearchColumnName in the web page in which we are consuming this custom control like below. Before consuming I registered this control in web page with register tag.

<ncc:SearchControl runat="server" ID="txtSearchControl" /> In code behind file of this webpage I am using following code to set the values.

protected void Page_Load(object sender, EventArgs e)
{
  txtSearchControl.ImageURL = "_layouts/Images/settingsicon.gif";
  txtSearchControl.SearchTableName = "Employees";
  txtSearchControl.SearchColumnName = "LastName";
  txtSearchControl.SiteURL = "http://Sp2010:8787";
 }

Now coming to the problem, when I click the image button the SearchTableName and SearchColumnName values are not coming. I think I am calling OnClientClick function, thats why the values are not being set. But how to set the values for the custom control based on the values setting in the webpage. If I use the Click function will it serve my purpose? If so, how to call that javascript function from this click event.

1 Answer 1

1

Finally got solution. I am initializing the values in the page init method in the custom control. Thats why the values i am setting in the visual webpart page are not being captured. Now I changed the initializing the values in CreateChildControl method. Now it works perfectly. Thank you.

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

Comments

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.