ASP.NET (RSS)

Migrate from Beta to Visual Studio 2005 RTM in a jiffy

Refering to my previous post here, I received some comments on what exactly to do when "nothing seems to work"....

Here is what to do :

You need to get the aspnet_regsql running and remove the aspnet tables from your database. (To run this just go to the C:\WINNT\Microsoft.NET\Framework\v2.0.50727> dir (or whatever version of beta you have, and type aspnet_regsql. Follow the wizard are select the table to remove the aspnet tables from)

For this you need to make sure that the aspnet tables are empty. You can use this script to get all the data cleared : (WARNING!!!! -> all your aspnet data will be lost i.e Users, roles, etc)

truncate table aspnet_Membership
truncate table aspnet_PersonalizationAllUsers
truncate table aspnet_PersonalizationPerUser
truncate table aspnet_Profile
truncate table aspnet_SchemaVersions
truncate table aspnet_WebEvent_Events
truncate table aspnet_UsersInRoles
truncate table aspnet_Applications
truncate table aspnet_Paths
truncate table aspnet_Roles
truncate table aspnet_Users

For some cases, the last 4 tables wont let you truncate, in this case go to those 4 tables and delete off the foreign keys and try truncating again.

After you have removed the data and used aspnet_regsql to remove the aspnet tables from your db, get a backup of this db and move it to a server which has RTM version installed on it and again run the aspnet_regsql but this time choose the new db over which you restored your backup and create aspnet tables.

Change the connection string of your app and try running it on the new db

Thats it! You're done....

Thank you for your mails, I will try my best to answer them and assist you, so don't hesitate to drop me a line...

Cheers!

Moving from Visual Studio 2005 Beta to Visual Studio 2005 RTM

I was shocked when i moved from Beta to RTM! My whole project was down! Couldn't even Debug! And the next day is Demo! After many agonizing hours of trying everything I could think of or could find on the net. I gave up and went down to a walk. When I came up, I gave it a last shot and Shekhar from BetaOne Services gave me this and this which saved the day.

Thanks Shekhar!

Anyways, if you are in the process of migrating as well, I strongly advice you read read what Scott Guthrie has to say about the RTM version  and the Breaking Changes file (also present in the read me) before you proceed....

Cheers!

UserControl/dynamic usercontrol cant be recognised!!

I was using a usercontrol on the master page and all the content pages were able to reference that control and manipulate it successfully. But then, sometimes, VS will thro errors saying that the user control references on "some" content pages cannot be recognised. Are u missing a reference or an assembly??

Huh?? it was working just during the previous build! What on earth did I do to make it throw an error??

Well, i got latest for all the files and asked everyone on my team to check in their files, got latest for all files and recompiled! Surprise, surprise! It works! No more error... The error is gone, just like that...

It was getting frustating... After some sniffing around, this is what i found.

In the content aspx page, you need to add a <%@ Reference %> directive for the usercontrol on the master page that you manipulate from the contect page. This is actually the same case when you are dealing with dynamically loaded usercontrols or pages with no code-behind classes...

Just in case you'd like to read further; check out Scott Gu's Blog post on Compatibility Testing with ASP.NET 2.0.

Cheers!

ASP.Net 2.0 membership error - Create new user

At some point you must have used the "Administer Website" option in order to create a user, and right when u enter the details and click to create a user, VS throws this error :

An error was encountered. Please return to the previous page and try again.

The following message may help in diagnosing the problem: Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at
System.Web.Administration.WebAdminMembershipProvider.
 GetWebAdminMembershipProviderHelperProperty(String propertyName) at
System.Web.Administration.WebAdminMembershipProvider.
 get_MinRequiredNonAlphanumericCharacters() at
System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() at
System.Web.UI.WebControls.CreateUserWizard.
 OnNextButtonClick(WizardNavigationEventArgs e) at
System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) at
System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) at
System.Web.UI.WebControls.Wizard.WizardChildTable.
 OnBubbleEvent(Object source, EventArgs args)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) at
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at
System.Web.UI.WebControls.Button.System.Web.UI.
 IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) at System.Web.UI.Page.
 RaisePostBackEvent(NameValueCollection postData) at
System.Web.UI.Page.ProcessRequestMain
(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Looks familiar?

This is a problem, but not exactly what the error describes...

For a quick fix just make sure that you use a password meeting the requirements of the password settings. For the default password settings, a password like "RohanT!" would suffice... There you go! Now you can create users successfully.... :)

P.S : You also can also change the password settings if you dont wanna type the special character everytime ;)

Cheers!

Configure WebParts as a menu in the Masterpage!!

For long time we have been trying to use webparts in our application's menu. Something like what My MSN does. But an interesting observation is that all the web part links to pages that open up on seperate pages. But in our application: webparts are located in the master pages and all the links in the webparts are supposed to open up in the content pages, we have may webparts according to the different modules and each webpart contains serveral links pertaining to that module. So far so good; no probs. But then comes the moving around of webparts. Once the user moves around the webpart menus according to his own convenience, it should stay the same for all pages! But we found out that the webpart only stays the same for the particular aspx page that it was arranged for!! But what we are trying to do is to arrange the menu for all the pages for that particular user!

This kinda seemed impossible to achieve as the webparts are located in the masterpages and the personlization uses URL of the content page as the personlzation key!

So wondering how to achieve this? This is how my colleague got it to work!!!

You need to overwrite "System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider" class with your own custom class. You need to perform a small hack here when you get or set the path. You can now put the web part in the master pages, drag, minimize, etc and when you navigate to a different page, the same arragement of webparts will be displayed. You just need to ensure the web.config is pointing to this custom class for personalization.

Web.Config:

Custom SqlPersonalization:
public class CustomSqlPersonalizationProvider : SqlPersonalizationProvider
{

private string GetPath
{
get{return "default.aspx";}
}

protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob)
{
base.LoadPersonalizationBlobs(webPartManager, this.GetPath, userName, ref sharedDataBlob, ref userDataBlob);
}

protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob)
{
base.SavePersonalizationBlob(webPartManager, this.GetPath, userName, dataBlob);
}

protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName)
{
base.ResetPersonalizationBlob(webPartManager, this.GetPath, userName);
}
}

This solution has also been published in the asp.net forums

Enjoy!

Modal Pop-Up window(ASP.NET JavaScript)

--------------------
Note : Ported over entry from my old blog, dated : 23rd - Feb - 2005
--------------------

Problem:
We all require Modal Web Dialogs once in a while, and so came my turn. I used js to pop up a modal dialog like so :

function OpenModalDialog(strUrl,strFeatures,aID,hours)
{
 if (strFeatures == '')
  strFeatures = "resizable=no;dialogWidth:510px;dialogHeight:350px;
                        help:no;maximize:yes;minimize:yes;scrollbars:yes";
 //set the cookie values
 document.cookie = "AID=" + aID + ";path=/";
 document.cookie = "Hours=" + hours + ";path=/";
 var r = window.showModalDialog(strUrl,'',strFeatures);
 if(r == true)
 {
  document.Form1.txhBool.value = '1';
 }
 else
 {
  document.Form1.txhBool.value = '0';
 }
 document.Form1.submit();
}

This function pops-up a modal web dialog. Now you have the modal dialog floating on top of the browser.
I wrote a few lines of code on the modal dialog and put a button in to make it submit. But to my surprise, another window(non-modal) poped up. I was very surprised and tried to get help but was told that modal dialogs cannot do a postback... Well I was very surprised at MS to let a loophole like this exist in IE. But I just continued my work due to lack of time to do some R&D. So now the only option was using js, so I used this function in my popup dialog and called it on the click on a <input> button (not asp button - as using asp button would force a postback!)
function ClosePopUp(val)
{
 window.returnValue = val;
 window.close();
}

What this fn does, is to pass the value val to the parent browser's function that poped this modal dialog up.
Lamentations :
So I process the value that is retrurned by the modal dialog and continued the processing on the parent page. The down side of this way according to me were three-fold.
1)All process had to be done on the page load of the Parent page(becuase the js function does a postback after getting a value from the child modal dialog.
2)A lot of time was wasted due to the fact that processing had to passed to the parent
3)The page modal was not so elegant
Many chances came where I needed to use modal dialogs, and all the way I used this method, thinking all this while that modal dialogs can't postback. Little did I know that I was so wrong!
Resolution :
Earlied when I was helping a person on one of the forums, Eliyahu Goldin, told me so!!
He said all I needed to do is to add this line inside the <head> </head> tag of the modal page :
<base target=_self>
Without wasting a second I opened one of the projects with the former js modal dialog implementation and tested it, and it worked totally!!!
So much time wasted, so much pain suffered just becuase I didn't bother to google for this one little piece of code! :(
I owe this to Eliyahu...Cheers man..