Cómo hacer referencia a los controles de una MasterPage en ASP.NET

Cómo hacer referencia a los controles de una MasterPage en ASP.NET

En este artículo veremos cómo hacer referencia a las propiedades de los controles de una página maestra desde nuestra página web.

Utilizaremos el método FindControl, para buscar y hacer referencia al control de la Página Maestra.

En el ejemplo siguiente se muestra el uso del método FindControl para obtener una referencia a dos controles de la página maestra, un control TextBox y un control Label. Dado que el control TextBox está dentro de un control ContentPlaceHolder, debe obtener primero una referencia a ContentPlaceHolder y, a continuación, utilizar su método FindControl para buscar el control TextBox.


Dim mpContentPlaceHolder As ContentPlaceHolder
    Dim mpTextBox As TextBox
    mpContentPlaceHolder = _
        CType(Master.FindControl("ContentPlaceHolder1"), _
    If Not mpContentPlaceHolder Is Nothing Then
        mpTextBox = CType(mpContentPlaceHolder. _
            FindControl("TextBox1"), TextBox)
        If Not mpTextBox Is Nothing Then
            mpTextBox.Text = "TextBox found!"
        End If
    End If

    ' Gets a reference to a Label control not in a 
    ' ContentPlaceHolder
    Dim mpLabel As Label
    mpLabel = CType(Master.FindControl("masterPageLabel"), Label)
    If Not mpLabel Is Nothing Then
        Label1.Text = "Master page label = " + mpLabel.Text
    End If


// Gets a reference to a TextBox control inside 
    // a ContentPlaceHolder
    ContentPlaceHolder mpContentPlaceHolder;
    TextBox mpTextBox;
    mpContentPlaceHolder = 
    if(mpContentPlaceHolder != null)
        mpTextBox = 
            (TextBox) mpContentPlaceHolder.FindControl("TextBox1");
        if(mpTextBox != null)
            mpTextBox.Text = "TextBox found!";
    // Gets a reference to a Label control that not in 
    // a ContentPlaceHolder
    Label mpLabel = (Label) Master.FindControl("masterPageLabel");
    if(mpLabel != null)
        Label1.Text = "Master page label = " + mpLabel.Text;



Comentarios (28)

  • joel peña Responder

    Referencia a objeto no establecida como instancia de un objeto.

    Tuesday, May 26, 2015 1:29 PM
  • Ignagher Responder

    Gracias me sirvió muchisimo

    Friday, October 7, 2016 10:59 AM
  • http://www.cheapnfljerseysdiscount.us.com/ Responder

    As the longest standing employee, he has been a roll-up-your-sleeves participant in the enormous changes that have come to the game and the SCGA. For instance, in central Texas where they are concentrated prices can go as low as 7 cents per kilowatt, the lowest in the state.S. The Detroit Lions are another team that struggles last year. Several of these merchandise is made with cold temperatures taken into account, as well as others, as an example the classy tote and also other handbags, are great for any kind of weather.

    Friday, June 30, 2017 2:05 PM
  • Ostermann Responder

    Actually no matter if someone doesn't be aware of after that its up to other visitors that they will assist, so here it takes place.

    Sunday, July 9, 2017 7:51 PM
  • Jarnigan Responder

    Way cool! Some very valid points! I appreciate you penning this write-up plus the rest of the site is very good.

    Monday, July 17, 2017 9:43 AM
  • Pilarbcn Responder

    Muy bueno y funciona a la primera. Gracias!!!

    Sunday, July 23, 2017 5:30 AM
  • Timmons Responder

    It's an amazing article in support of all the online visitors; they will take advantage from it I am sure.

    Wednesday, August 30, 2017 2:26 AM
  • Neill Responder

    Hello very nice website!! Man .. Beautiful .. Superb .. I will bookmark your web site and take the feeds additionally? I am happy to seek out numerous helpful information right here within the put up, we'd like develop more strategies on this regard, thank you for sharing. . . . . .

    Saturday, September 2, 2017 2:05 PM
  • Peach Responder

    Does your website have a contact page? I'm having trouble locating it but, I'd like to shoot you an email. I've got some recommendations for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it expand over time.

    Sunday, September 10, 2017 8:52 PM
  • Du Faur Responder

    Guest blogging is still one of the finest ways to build backlinks.

    Wednesday, September 20, 2017 10:56 PM
  • Mathis Responder

    legit online loans loan companies how to borrow money fast

    Tuesday, September 26, 2017 10:52 AM
  • Bess Responder

    Hmm is anyone else experiencing problems with the pictures on this blog loading? I'm trying to figure out if its a problem on my end or if it's the blog. Any feedback would be greatly appreciated.

    Saturday, September 30, 2017 5:53 PM
  • Stedman Responder

    payday loans lakewood co short term bad credit loans 1500 dollar loan

    Tuesday, October 3, 2017 1:35 PM
  • Fitzmaurice Responder

    I w?nted t? putt you that litt?e w?r? just to sayy thank you aga?n for the?e incredible principles ?ou'?e contributed ?t th?s time. This has be?n ?ertainly shockingly generous ?ith yo? giving easily wh?t mo?t people w?uld've supplied as an electronic book t?o he?p ?ith making some cash oon th?ir own, prima?ily c?nsidering that you might have done it in the event ?o? wante?. The smart ideas l?kewise served ?s the great ?ay t? realize that someone ?lse h?ve sim?lar eagerness m?ch ?ike my very own to know ? grea deal more pertaining t? th?s matter. Certzinly there are millions of morte pleasurable moments ?n the future ffor individuals that ?oo? over your blog. I wish to express my thanks t? this writer f?r bailing mme ?ut of th?s part?cular circumstance. ?ecause of exploriing th?ough thee internet and seeing advice ?hich were not beneficial, ? assummed m? ent?re lofe ?as gone. Living m?nus the solutions to th? pr?blems you've sorted out by w?y of your good site ?? ? crucial case, ass ?ell ass th?se ?hich c?uld hzve in ? negative ?ay ?ffected my entir? career iif I hadn't encountered ??ur website. Your ?wn training and kindness in handling every iteem ?as excellent. ?'m not sure what I w?uld have done if I hadn't encountered such a thing l?ke this. ? caan also at this time relish my future. ?hanks very m?ch f?r this high quality and result orfiented help. ? ?ill nnot be reluctant to endorse ??ur blog post to anybody wh? sho?ld have tips on th?s problem. I jyst wanted to wr?te down a br?ef comm?nt to bbe agle to saay thanks to yyou for these amazing ideas ?ou are showing at thi? site. ?y rather ?ong internet search has fina?ly b?en honored with rea?ly good ?oints to write about with my friends ?nd family. I 'd assume th?t most of us readers ?ctually a?e very endowed to dwell ?n a perfect network w?th many special people ?ith very helpful strategies. ? feel r?ther privileged to have encountered the webpage ?nd l?ok forward to rea?ly more amazing t?mes reading here. Thanks a ?ot ag?in for all the details. ?hanks ?o mu?h f?r providing individuals ?ith remarkably splendid opportunity t? read articles ?nd blog posts from here. ?t ?s ?ften so ideal plus ful? ?f amusement fo? m? personally and m? office co-workers to search y?ur site ?articularly 3 time? ? week to read the new?st guidance you will have. ?nd of course, we a?e ?sually fascinated ?onsidering the sensational techniques ??u give. Certain two tips in th?s posting ?re certainly the ?est we h?ve all e?er had. I have to convey my respect for y?ur kindness giving support t? people who ?eally want h?lp with thi? study. ?our real dedication t? passing the message all th?ough has been rath?r powerful and has consistently helped people l?ke me to realize their endeavors. Your ?mportant u?eful ?nformation signifies ? wh?l? lot to me and mu?h m?re t? my colleagues. Regards; from each ?ne of us. I in ad?ition to my friends ?ere a?tually examining the good guidelines f?und on your site while at once came up ?ith an awful suspicion I nev?r expressed respect t? the site owner for tho?e strategies. ?he people ?re actual?y a? a result excited to learn ?ll of them and hav? no? rea?ly ?een having fun with them. Thank yo? f?r ind?ed ?eing simply helpful ?nd al?o for settling on thi? form of essential issues mo?t people a?e r?ally eager t? b? aware of. Our own honest apologies f?r not expressing appreciation t? you sooner. I am glad for writing to let you be aware of of the excellent discovery m? daughter undergone visiting ?our blog. She figured out m?ny issues, which included what it is like t? possess an amazing giving nature to get the rest with no trouble ?now j??t exactly several advanced topics. ?ou ?eally exceeded readers' desires. ?hank yo? fo? providing th? effective, safe, explanatory not tto mention unique tips ?bout the topic to Julie. I simply h?? to a?preciate yyou ?et again. I am not sure what I might have undertaken withhout the actual points pr?vided b? yo? concerning mmy situation. ?t seemed to b? a real frightful setting in my view, neverth?less taking note of thhe very expert ?ay you resoklved th?t forced m? to cry with contentment. Noww i am grateful foor the hel? and ev?n expect yo? find outt what ?n amazing job yo? h?ve been providing training m?n and women all through a site. Moree th?n ?ikely yo?'ve never got t?o know any ?f us. M? husband and i wer? lucky Albert could round up hi? investigation ?ia th? precious recommendations hhe ade f?om y?ur own site. It'? not at ?ll

    Saturday, October 7, 2017 11:27 PM
  • Emery Responder

    I am extremely impressed with your writing talents and also with the layout for your weblog. Is that this a paid subject matter or did you modify it yourself? Anyway stay up the excellent quality writing, it's uncommon to look a nice blog like this one nowadays..

    Wednesday, October 11, 2017 11:17 PM
  • Cavalcanti Responder

    Esta página certamente tem todos os informações e fatos queria respeito deste de assunto e não sabia a quem perguntar.

    Saturday, October 14, 2017 4:02 AM
  • Cavalcanti Responder

    Esta página certamente tem todos os informações e fatos queria respeito deste de assunto e não sabia a quem perguntar.

    Saturday, October 14, 2017 4:06 AM
  • Booze Responder

    This post provides clear idea designed for the new viewers of blogging, that actually how to do blogging and site-building.

    Wednesday, October 18, 2017 8:47 AM
  • Brigham Responder

    Thanks for revealing ?o?r ideas. I'? also llike to express that video games have ?een ev?r befo?? evolving. Modern toolls ?nd inventions have m??e ?t easier t? create sensi?l? and enjoyable games. ?ll th?se enterrtainment games ?ere not actu?lly ?ensible ?hen the real concept ?as fi?st being experimented ?ith. ?ust ?ike other ?ind of electronics, video games a?so have had tto grow ?s a result ?f many ages. ?his ?tself ?s testimony t? the fa?t development of video games. ?'ve observed in the w?rld the?e days, video games will be the lat?st rag ?ith kids of all ages. The?e a?e t?mes when it may be extremely hard to drag yo?ng kids a?ay fr?m the activities. ?f you ?ant the best ?f both worlds, the?e ar? plenty of educational games f?r kids. ?hanks f?r ?o?r post. An additional issue is that video games are typically se?ious as the nam? indicate? with th? main focus ?n studyimg ?ather than leisure. Although, there's an enteetainment element t? keep the kids engaged, ?ach game is norm?lly designed t? work towards a specific experience or curriculum, ?uch as mathmatical ?r scfientific discipline. Thanks for your publication. ? have learned ?ome p?ints th?ough y?ur site post. ?ne other subject ? woul? luke too talk about is th?t the?e a?e sever?l games avail?ble ?nd which are designed ?articularly f?r toddler age young children. Theey consist ?ff pattern acknowledgement, colors, wildlife, ?nd patterns. ?hese generaly focus on familiarization ?s an alternative to memorization. ?his m?kes children aand kids engaged ?ithout having ? sensation ?ike they ?r? studying. ?hanks A furth?r issue is that videeo gaming became one of the all-time main forms of entertainment f?r people of ?arious age ?roups. Kids enoy video games, ?lus adults ?o, too. The XBox 360 is ?robably tthe favorite gaming systems f?r m?ny who love to have a h?ge variety ?f video games ?vailable t? them, and a?so ?ho lik? t? reelax ?nd play live w?th peope ?ll ?ver the world. ?hanks for shaing your thinking.

    Friday, October 20, 2017 1:45 AM
  • Mount Responder

    Business Visa is offered to the foreigners who intend to do business in Nepal, and those who have obtained license to make investment in Nepal.

    Saturday, October 28, 2017 6:56 AM
  • Halsey Responder

    Unquestionably consider that that you said. Your favourite reason seemed to be at the net the simplest factor to understand of. I say to you, I certainly get annoyed even as other people think about concerns that they plainly don't understand about. You managed to hit the nail upon the highest and outlined out the entire thing with no need side-effects , other folks could take a signal. Will probably be back to get more. Thanks

    Tuesday, November 14, 2017 12:34 AM
  • Paten Responder

    My brother suggested I might like this web site. He was entirely right. This post truly made my day. You can not imagine simply how much time I had spent for this information! Thanks!

    Saturday, November 18, 2017 12:19 PM
  • Ortiz Responder

    Excellent site you've got here.. It's hard to find excellent writing like yours these days. I honestly appreciate individuals like you! Take care!!

    Saturday, November 18, 2017 4:13 PM
  • Parrish Responder

    casino site casino online 888 free play online Pokies best uk slot sites

    Monday, November 20, 2017 12:29 AM
  • Barkley Responder

    free casino slot games with bonus rounds no deposit bonus mandarin palace casino x bonus code gambling addiction nz free online casino games

    Tuesday, November 21, 2017 6:31 AM
  • Whitehouse Responder

    signature loans online i need money today online bad credit loans no credit loan direct lenders

    Saturday, November 25, 2017 11:53 AM
  • Macknight Responder

    Very easy to get.

    Monday, December 4, 2017 9:10 AM
  • Clary Responder

    It is not my first time to go to see this website, i am visiting this web page dailly and get fastidious facts from here daily.

    Monday, December 11, 2017 8:57 PM

Animate deja un comentario!!!

Eres un humano?

Últimos Tweets


  • Dirección: Plutarco Elias Calles 243, Granjas México, Iztacalco, DF.

  • Teléfono:55-2712-3820 o 55-4164-9484

  • Email: info@developerji.com