Results 1 to 16 of 16

Thread: is this wrong ?

  1. #1

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    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

  2. #2
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    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)


  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  4. #4
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    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. :-(


  5. #5
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448


  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: is this wrong ?

    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

  7. #7

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    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

  8. #8
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448


  9. #9

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: is this wrong ?

    page not found ?
    * 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

  10. #10
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Re: is this wrong ?

    oi...cached version...ugly, but must read: http://74.125.153.132/search?q=cache...ient=firefox-a


  11. #11
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  12. #12

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    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

  13. #13
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: is this wrong ?

    Quote Originally Posted by motil View Post
    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

  14. #14

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    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

  15. #15
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: is this wrong ?

    Quote Originally Posted by motil View Post
    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
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  16. #16

    Thread Starter
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    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
  •  



Click Here to Expand Forum to Full Width