|
-
Mar 15th, 2010, 05:45 PM
#1
is this wrong ?
Ok so every now and then i finding myself in a situation where i need to pass tons of "Control.ClientID" from one JS function to another just because the way ASP.NET dynamically change the controls ID's so for example instead of having nice clean function like this
Code:
btnSignUpSubmit.Attributes.Add("onclick", String.Concat(return FormValidation());
i'm ending up with this:
Code:
btnSignUpSubmit.Attributes.Add("onclick", String.Concat(return FormValidation('", COSelectedLanguage.GetLanguageClientID, "','",
ddlSelectLeague.ClientID , "','", ddlSelectRegion.ClientID , "','" ,txbTeamName.ClientID, "','" ,txbLoginName.ClientID
,"','",txbPassword.ClientID, "','" ,txbConfirmPassword.ClientID, "','",txbEmail.ClientID,
"','", txbConfirmEmail.ClientID,"','" ,chbAgree.ClientID ,
"','", hdfisExistTeamName.ClientID,"','",hdfisExistLoginName.ClientID,"','",btnSignUpSubmit.ClientID ,"','",btnSignUpPostBack.ClientID ,"')"));
if the ID's wouldn't change i could get them from within the JS code.
the solution i found for this is to give each of the controls fake (unique) CSS class and then i can get to each of this controls within the JS code without having to pass all of the id's ... is this bad practice?
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Mar 15th, 2010, 11:38 PM
#2
Hyperactive Member
Re: is this wrong ?
Uurgh...reminded me why I don't do Web Forms....everything is bad practice as it is.
The class names solely for the purpose you described would be frown upon in normal web development, but seems that's the way to go in this case.
Tip: Heard of that thing called Asp.Net MVC? (Used it since it's beta, and will never look back)
-
Mar 16th, 2010, 02:41 AM
#3
Re: is this wrong ?
Hey,
It certainly isn't pretty, but a necessary evil at the minute.
This will be "fixed" going forward with ASP.Net in .Net 4.0 where you can specify the ClientID. Not much longer to hold out for it 
Krokonoster, have you tried the latest release yet? Any major improvements, changes?
Gary
-
Mar 16th, 2010, 02:48 AM
#4
Hyperactive Member
Re: is this wrong ?
Latest of MVC? Yeah, had to and using it. The Area's are nice...but for the most part it's just things from MVCFutures and MvcContrib that became part of the new version.
Guess I'll pick up this Asp.Net 4.0 book....does not seems the world is going the MVC way, and I aint gonna get myself a proper new job. :-(
-
Mar 16th, 2010, 02:50 AM
#5
Hyperactive Member
-
Mar 16th, 2010, 02:52 AM
#6
Re: is this wrong ?
 Originally Posted by Krokonoster
Yeah, I am subscribed to Scott's Blog, and have read his post, but was just looking for some hands on feedback. I haven't played with it enough personally to form an opinion about it.
Gary
-
Mar 16th, 2010, 04:31 AM
#7
Re: is this wrong ?
Can someone please explain a bit about MVC? can you combine it with "classic" ASP.NET? what is the benefits? what do you need to change in your project so you can use MVC ?
all in all i'm all good with ASP.NET environment but did this this fatal mistake with the dynamics IDs ... they should never apply this method and they HAD to fix it with the .NET 2.0/3.5 release's .... (what did they thinking???)
Gary i have two questions: how long will it take for the release of .NET 4.0 ?
and do you know how did they handled the id's when you use repeater for example in .NET 4.0? do you get to choose prefix or suffix ? for example if you give an ID of a Textbox inside a repeater an ID of "txbMyTextBox" i should be able to choose some kind of suffix to it like "_" and when the page will get rendered all the IDs should be numbered like "txbMyTextBox_1,txbMyTextBox_2 ..."
i hope its going to be something like this and not this ugly long IDs
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Mar 16th, 2010, 04:43 AM
#8
Hyperactive Member
-
Mar 16th, 2010, 04:52 AM
#9
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Mar 16th, 2010, 04:57 AM
#10
Hyperactive Member
-
Mar 16th, 2010, 05:07 AM
#11
Re: is this wrong ?
Instead of String.Concat, using the String.Format should result in a cleaner code.
Also if your page is asp.net ajax enabled, you can use $get() directly.
-
Mar 16th, 2010, 05:10 AM
#12
Re: is this wrong ?
Pradeep what do you mean by using the $get? isn't jquery method?
can you post link with example?
Thanks.
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Mar 16th, 2010, 05:28 AM
#13
Re: is this wrong ?
 Originally Posted by motil
Can someone please explain a bit about MVC? can you combine it with "classic" ASP.NET? what is the benefits? what do you need to change in your project so you can use MVC ?
all in all i'm all good with ASP.NET environment but did this this fatal mistake with the dynamics IDs ... they should never apply this method and they HAD to fix it with the .NET 2.0/3.5 release's .... (what did they thinking???)
Gary i have two questions: how long will it take for the release of .NET 4.0 ?
and do you know how did they handled the id's when you use repeater for example in .NET 4.0? do you get to choose prefix or suffix ? for example if you give an ID of a Textbox inside a repeater an ID of "txbMyTextBox" i should be able to choose some kind of suffix to it like "_" and when the page will get rendered all the IDs should be numbered like "txbMyTextBox_1,txbMyTextBox_2 ..."
i hope its going to be something like this and not this ugly long IDs
Hey,
.Net 4.0 is slated for release this year. Last I heard it was middle of April.
The exact details of how it is going to work, I am not sure, but take a look here:
http://weblogs.asp.net/scottgu/archi...-4-series.aspx
I am fairly sure it was covered.
Gary
-
Mar 16th, 2010, 06:07 AM
#14
Re: is this wrong ?
i ended up reading about it here http://www.onedotnetway.com/working-...-in-asp-net-4/
the sad part is that it's only partial fix... it's amaze me how they ignore this problem...
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Mar 16th, 2010, 06:39 AM
#15
Re: is this wrong ?
 Originally Posted by motil
Pradeep what do you mean by using the $get? isn't jquery method?
can you post link with example?
Thanks.
No it is not jquery.
It is asp.net ajax method. If you include a <scriptManager> object on your form, you get a few additional functions like $get() and $find() for use in javascript.
$get() is basically same as Document.GetElementById() but it has some enhanced intelligence built into it.
I found this useful link that has good explanation with examples:
http://mattberseth.com/blog/2007/08/...d_find_as.html
-
Mar 16th, 2010, 06:52 AM
#16
Re: is this wrong ?
Thanks Pradeep but its not what i'm up to 
i'm also trying to avoid <scriptmanager> and <updatepanel> controls since i don't really like to use what i'm not have total control of, and in my opinion these controls just adding a lot of extra and unneeded content to your pages.
using these controls saves you work but from my experience they can also get you into a lot of troubles. i might dive a bit into MVC when i'll time to read about it, for the meanwhile i'll just have to manage with the tools i have and be creative .
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|