Friday, January 04, 2008
ModalPopUpExtender – Multiple controls And One Modal
Although the idea behind the modalpopupextender is a very good one, unfortunately this control's usage is not as straight-forward as its designers would've hoped. Whilst in most cases it is true that you can just drop the extender on the page and set its declarative properties to point to the right panel and button triggers, in the more complex cases, such as when the extender inside a GridView, you have to apply some workarounds.
Apparently the ability of setting multiple targets for the modalpopupextender existed at one point in time in one of the beta Atlas releases, however, the team deemed it too complex and didn't include it in the final release when it became ASP.Net Ajax. So how to work around it?
There are a couple of ways to do this, but the solution is forcibly the same: you gotta use javascript.
What I do is set the modalpopupextender to one of the controls and then any other controls that need to use the same modal I add some javascript to the OnClientClick property which finds the extender control and calls the show() method on it.
<asp:LinkButton
runat="LinkButton1"
runat="server"></asp:LinkButton>
<asp:LinkButton
runat="LinkButton2"
runat="server"
OnClientClick="$find('DisplayPurchaseInfoModalPopupExtender').show();return false;"></asp:LinkButton><cc1:ModalPopupExtender
ID="ModalPopupExtender1"
runat="server"
TargetControlID=" LinkButton1"
PopupControlID="PanelModalWindow"></cc1:ModalPopupExtender>
If the modalpopupextender control is inside a template in a GridView, you will have to do this in the DataBound event, since otherwise you won't be able to find out the real name of the extender control.
So, when using a GridView you'd set the OnClientClick property of whatever controls that are going to use the modalpopupextender by doing something like this:
LinkButton linkButton2 = (LinkButton) e.Item.FindControl("LinkButton2");
linkButton2.OnClientClick = string.Format("$find('{0}').show();return false; e.Item.FindControl("DisplayPurchaseInfoModalPopupExtender").ClientID);
Sunday, February 11, 2007
Error "The row doesn't belong to the same DataSet as this relation." when using DataRelation
C#
DataSet dt = new DataSet();
DataRelation dr = new DataRelation("test",dt.Tables[0].Columns[0],dt.Tables[1].Columns[1]);
//now this is probably what you forgot to do
dt.Relations.Add(dr);
Friday, January 26, 2007
Lost Intelllisense in web.config in Visual Studio
To restore the Intellisense just delete the namespace declaration so that the configuration element has no attributes, like so:
That namespace declaration can be added by the Web Configuration tool, for example, or any other tool, or developer that might have meddled with the xml on the file.
Monday, January 22, 2007
Server Application Unavailable
Go to IIS, look at the properties of your virtual directory or web site, and then go to the ASP.Net tab. There make sure that the web site is set to run under the right versio of ASP.Net.
Wednesday, January 17, 2007
One year after Microsoft's release of patterns & practices for Smart Client development, finally ASP.Net get is own software factory!
I have used the Smart Client Software Factory quite substantially and, having loved it, was always frustrated about the fact that there wasn't something nearly as good for web-based development. In fact, I even tried to come up with a similar architecture for ASP.Net trying to reproduce some of the concepts of the Smart Client Factory into a web scenario, but after a few frustrating shortcomings I decided just to wait for them to come out with one.
I haven't looked at it yet, but I am in the process of downloading it right now and I intend to experiment with it and blog my findings here.
I have high expectations for it, I just hope it doesn't dissapoint. I just think web-based development has been crying desperately for a unified best-practices architecture with design patterns applied. Let's just hope this is it!
Wednesday, September 27, 2006
Those of you using the Microsoft.ApplicationBlocks classes for your DAL might already have noticed (or not! which is the point of blogging about this) that the SqlHelper.FillDataset() method has many overloads some of which take a string array, supposedly to be used to automatically name the DataTables on the dataset for multiple recordsets returned.
While this seems handy in theory, it doesn't actually work cuz the method's got a bug. No matter how many strings you put into the array, the method will only name the first two tables accoding to what you have entered. After that it will name them as "Table" plus their index on the tables collection.
so, if you have 4 resultsets being returned and you pass in the following array for the tablenames arguments:
new string[] tablenames { "Red", "Green", "Blue", "Yellow", "Black" }
the tables on the dataset will actually be named : "Red", "Green", "Table2", "Table3" and "Table4"
To get around this, I reccomend looping through the dataset right after the fill so everything is still isolated on the DAL, after all, this is the DAL's job and it should've been done in first place anyway if it wasn't for Microsoft releasing it with a bug.
so what I do first is set up an array with all the table names . Then right after the fill loop through the tables collection and set every table to their right name.
C#
string[] tablenames { "Red", "Green", "Blue", "Yellow", "Black" };
for (int i=0;i < dt.Tables.Count; i++) { dt.Tables[i] = tablenames[i]; }
You might then wonder what to do with the tablenames argument in FillDataset(). Well, you can do whatever you want since it won't matter, however, just for clarity, I like to make it as if it actually work and properly pass in the same tablenames colletion I use to rename the tables and add a comment flagging the bug.
Wednesday, September 20, 2006
I was going to blog write an article about Isolated Storage but then I ran into something I wasn't so sure about and went on the net to research. Not surprisingly I found many articles about it and even though I usually don't mind writing my own even if there are many out there already, after all each person can provide different insights or ways to explain something, I suppose sometimes there is just no point in doing it since some of them are just impossible to be done better.
This is the case with this article by Chris Tavares on Isolated Storage.
Check it out on: http://www.dotnetdevs.com/articles/IsolatedStorage.aspx
