Wednesday, October 15, 2008

Update Panel intricacies

While experimenting with multiple update panels on a single page there were certain weird things that I observed.
1.) Duplicate controls created: I had placed a label within an update panel like below:
< tr >
< asp:updatepanel id="UpdatePanel3" runat="server" updatemode="Always" rendermode="Block">
< contenttemplate>
< td colspan="2">
< asp:label id="Label1" runat="server" text="Test Label">
< /td>
< /contenttemplate>
< /asp:updatepanel>
< /tr>


And somewhere else in the page:

< tr>
< td style="WIDTH: auto">
< asp:dropdownlist id="DropDownList1" runat="server" autopostback="true">
< asp:listitem>One
< asp:listitem>Two
< asp:listitem>Three
< asp:listitem>Four
< asp:listitem>Five
< /asp:dropdownlist>
< /td>
< td style="WIDTH: auto">
< asp:updatepanel id="UpdatePanel2" runat="server" updatemode="Conditional">
< contenttemplate>
< asp:textbox id="TextBox1" runat="server">
< /contenttemplate>
< triggers>
< asp:asyncpostbacktrigger controlid="DropDownList1" eventname="SelectedIndexChanged">
< /triggers>
< /asp:updatepanel>
< /td>
< /tr


Now whenever an AJAX postback happened, the page will have two lables shown to it. I found that if put the property RenderMode="Inline" in UpdatePanel1, the label is no more duplicated. It would be worth noting that the "Block" RenderMode renders two labels, as well. In the source of the HTML I found that the "Inline" mode renders the UpdatePanel in < span>tags while the "Block" mode renders the UpdatePanel in < div>tags.

The problem goes away if the < td>is wrapped around the UpdatePanel. So after modifying the first HTML to

< td colspan="2">
< asp:updatepanel id="UpdatePanel1" runat="server" updatemode="Always">
< contenttemplate>
< asp:label id="Label1" runat="server" text="Test Label">
< /contenttemplate>
< /asp:updatepanel>
< /td>


I do not need to explicitly set the RenderMode value to "Inline".

But why it happens? No idea.

Tuesday, April 8, 2008

Setting class property value at run time

While making a simple web user control, I thought of having a property that will pick up the controls on a page and then the based on what form/page control developer has assigned to the user control it will populate its property.

While looking to implement this I hit upon TypeConverter class, but somehow couldn't get this done. From a forum where I posted my question, I learnt that this is because my control inherits from UserControl class and not WebControl class and consequently can't implement TypeConverter. Though I'm not satisfied with this, I'm still to find a working solution.

One of the properties exposed by my user control was "PropertyToPopulate". The control on a page can be a textbox, a 3rd party control(Telerik in my case) or anything else, thus this property was required. I knew that I can set the property value through Reflection in .Net but while trying to find a sample code I came across codes which were very detailed and complex but none of my use. Finally, I was able to filter out things and combine it into one to achieve my objective. Below is what I did:

Dim control As New Object
control = CObj(Me.Parent.FindControl(_FromDateControl))
Dim controlType As Type = control.GetType()
Dim properties As System.Reflection.PropertyInfo
properties = controlType.GetProperty(_PropertyToPopulate)
properties.SetValue(control, newDate, Nothing)

The code above simply, finds the control gets it type and then the property that the user wishes to set. The SetValue() method does the trick of setting the value in the property.

And that was it.

Friday, April 4, 2008

Repeating label value with multiple row groups -- SSRS

I was getting this weird behavior on my reports wherever I'd two row groups and multiple column groups in a matrix report. The label that I'd set on to show for the row group (the other row group was an invisible row group to have alternate colors in the rows) was repeating twice when it was rendered on a web page. While the label will show only once on my local machine in preview mode in IDE. The report looked something like:



The Date row header that was showing twice was placed on the designed only once. Couldn't locate any instance where somebody else too had this issue.

So, finally I implemented a workaround to get away from this.
1.) Removed the text from the row group header text box.
2.) Put in a rectangle at that text box
3.) Put a text box within the rectangle and wrote the required text.

And there it was. The text was now appearing only once. Happy that I was able to get rid of it. Took me some time for this idea to strike.

Thursday, April 3, 2008

Reporting Services & IE7 scrolling issue

All the reports that I'd developed were working fine till the time they were tested on my PM's machine with Vista & IE7. On the spot, I was able to convince him that this is something specific to Vista and hence will need some more work (I could get off very easily with this).
But when I installed IE7 on my machine it was giving the same weird behaviour.. the columns to the right were not showing up.

Then I found this link: http://arcanecode.wordpress.com/2007/11/29/sql-server-2005-reporting-services-reportviewer-control-and-ie7/
(I know everybody looking for this issue will get this link prior to getting to my page; but just in case their site is scrapped then I got a chance). So, I'll repeat the steps (copyright remains with the original publisher I don't want it: This is my disclaimer).
a.) Remove the DOCTYPE tag in it's entirety from the ASPX page. Those with master pages don't have to worry. It won't be there.
b.) Set the AsyncRendering property to False for the ReportViewer control on aspx page. This is True by default. This did the trick in my case.
c.) Make sure the width of the ReportViewer control is set to 100% and remove any references to height property.

I needed to do only the second point as the 3rd was already done and 1st was not required because my page is a content page contained within a master page.

Hope this helps somebody someday!
Cheers (not of the weekend kinds)

UPDATE:
I noticed later that carrying out the above changes played havoc with my page layout. The text was getting out of the intended place and all.
So, to correct that I removed the width=100% and set it to a specific pixel width(against what's advised in the link above) I got everything corrected and received the scroll bars as well. After that I reset the "AsyncRendering" to "True" and it was still working fine. Can't explain for sure as to why it's so; but the only thing I've changed when I was getting the error and the correctly showing page is
a.) specifically set the "AsyncRendering" to "True", and
b.) removed the width=100% that was there earlier to a specific pixed width value.

Hope this helps somebody else as well.

The first one

The first posting has to be an introduction! I hope to keep posting all my issues here. Also, I plan to update all those issues with resolutions as and when I get them. They may come from various forums where I post them or through some other links or suddenly I find what was I doing wrong.

Any which way I presume this will help others to get a resolution to their issue (if ever this page comes up during their search). I'll see how I can popularize it.

I hope I keep up to what I've promised myself (generally I'm unable to do whatever I plan). Though first step is always taken.

I would also love if you post a question you're searching an answer for. For if I have it I'll provide it asap. The technologies I work on are: C#, VB.Net, ASP.Net, Reporting Services.