Friday, February 27, 2009

Sys.InvalidOperationExceptio in UpdatePanel in asp.net ajax due to control structure



I recently got this error: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'ctl00_QuoteContent_UpdatePanelSiteAddress'. If it is being updated dynamically then it must be inside another UpdatePanel. And I fixed it too! I was using updatepanel in my page to update certain part from the page. I googled much. [I could sagoon too!]. They suggest that disabling event validation in the page would solve the problem. But nope. Some even told that removing UpdateMode="Conditional" for the upatepanel would solve the problem. And nope again!


Why the Sys.InvalidOperationException with the above mentioned error occurred?


This happened to occur because I had tried to access (and modify property of) a control outside the updatepanel's contenttemplate. Let me show this.


Here goes the design page:

1. I have one dropdownlist (ddlAddressType).
2. Now I have a table with a row [row id trAddress]
3. Within this row I have one updatepanel.
4. In the updatepanel's ContenTemplate I have another table in which I have a gridview.
5. I have added ddlAddressType as the asychronous postback control for the updatepanel.

That's all. For quick preview, I want to hide the row trAddress which is outside the updatepanel itself. Got it?

Now see here the code behind page:

//on selected index changed
protected void ddlAddressType_SelectedIndexChanged(object sender, EventArgs e)
{
if(ddlAddressType.SelectedValue.Contains("--"))
{
//Here I had tried to access the row (set visibility false)
trAddress.Visible=false;
}
else
{
//Here I had tried to access the row (set visibility true)
trAddress.Visible=true;
}
}

Clearly, the row I am trying to make invisible is out of the scope of the updatepanel. So the error occurred.


Solution? In my case, I just set the table visible/invisible. Solved! Happy Programming

kick it on DotNetKicks.com

Monday, February 9, 2009

Upload and Crop Images with jQuery, JCrop and ASP.NET

Need to crop image before uploading, in asp.net? Sounds like the alternative to thumbnail generation in asp.net web page, right? Here goes the handy code using jQuery, JCrop and ASP.NET. Good luck!

I have coded a shopping cart in which there was the need of uploading images to the server, and keep the sizes as required by the content of the pages. In my case I had to hard-code the size of the thumbnail I generated. But wouldn't it be lovely if the site user could crop the image and fix the required size? So I have found one very useful way to Upload and Crop Images with jQuery, JCrop and ASP.NET. I hope this will be useful for all programmers.

Happy Programming!

Popular Posts

Recent Articles