Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

ASP.NET forma - fokus na kontrolu

[es] :: .NET :: ASP.NET :: ASP.NET forma - fokus na kontrolu

[ Pregleda: 2697 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Simke
Marko Simic
Sandfield Associates (Solution
Developer)
Novi Zeland

Član broj: 1158
Poruke: 751
*.avenue.co.nz

ICQ: 71578686
Sajt: www.sandfield.co.nz


Profil

icon ASP.NET forma - fokus na kontrolu01.03.2004. u 22:22 - pre 244 meseci
Kako da postavim fokus na kontorlu u ASP.NET formi? Focus metod nije dostupan. Problem je u tome sto recimo svaki put kada korisnik klikne na dugme, stranica skroluje na sam pocetak. Ako ne moze da se fokusira, moze li bar da stranica ostane tu gde je, a da ne skroluje na pocetak?
All beer is good. Some beer is better.
 
Odgovor na temu

degojs

Član broj: 4716
Poruke: 5096



+51 Profil

icon Re: ASP.NET forma - fokus na kontrolu02.03.2004. u 04:29 - pre 244 meseci
Što se tiče scroll-persistence, evo koda koji radi posao. Kako kaže, kod samo dodaj u svoju formu i pride jedno this.UseScrollPersistance = true i to je to. A što se fokusa na određenu kontrolu tiče, sigurno mora malčice JavaScript-a da se ubaci - pogledaj po Netu, primera bi trebalo da ima tonu.

Code:

//
// Add this code into your web form (i.e. WebForm1.aspx.cs)
// In your page_Load (or initialization) add this line:
// this.UseScrollPersistance = true;
//


#region Disclaimer
/**********************************************************************
Based on presentation by Brad McCabe of Infragistics

Updated by Scott Watermasysk (http://scottwater.com)

Provided as is, with no warrenty, etc.
Please use however you see fit. Just don't ask for a VB version :)
***********************************************************************/
#endregion

using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;


#region Scroll Persistence
        
private bool _useScrollPersistence = true;
        /// <summary>
        /// There could be PostBack senarios where we do not want to remember the scroll position. Set this property to false
        /// if you would like the page to forget the current scroll position
        /// </summary>

public bool UseScrollPersistence
        {
            get {return this._useScrollPersistence;}
            set {this._useScrollPersistence = value;}
        }

private string _bodyID;
        /// <summary>
        /// Some pages might already have the ID attribute set for the body tag. Setting this property will not render the ID or change
        /// the existing value. It will simply update the javascript written out to the browser.
        /// </summary>

public string BodyID
        {
            get {return this._bodyID;}
            set {this._bodyID = value;}
        }


        //Last chance. Do we want to maintain the current scroll position
protected override void OnPreRender(EventArgs e)
        {
            if(UseScrollPersistence)
            {
                RetainScrollPosition();
            }
            base.OnPreRender (e);
        }        

protected override void Render(HtmlTextWriter writer)
        {
            //No need processing the HTML if the user does not want to maintain scroll position or already has
            //set the body ID value
            if(UseScrollPersistence && BodyID == null)
            {
                TextWriter tempWriter = new StringWriter();
                base.Render(new HtmlTextWriter(tempWriter));
                writer.Write(Regex.Replace(tempWriter.ToString(),"<body","<body id=\"thebody\" ",RegexOptions.IgnoreCase));
            }
            else
            {
                base.Render(writer);
            }
        }

private static string saveScrollPosition = "<script language='javascript'>function saveScrollPosition() {{document.forms[0].__SCROLLPOS.value = {0}.scrollTop;}}{0}.onscroll=saveScrollPosition;</script>";

private static string setScrollPosition = "<script language='javascript'>function setScrollPosition() {{{0}.scrollTop =\"{1}\";}}{0}.onload=setScrollPosition;</script>";

        //Write out javascript and hidden field

private void RetainScrollPosition()
        {
            RegisterHiddenField("__SCROLLPOS", "0");
            string __bodyID = BodyID == null ? "thebody" : BodyID;
            RegisterStartupScript("saveScroll", string.Format(saveScrollPosition,__bodyID));

            if(Page.IsPostBack)
            {
                RegisterStartupScript("setScroll", string.Format(setScrollPosition,__bodyID, Request.Form["__SCROLLPOS"]));
            }
        }

        
#endregion


Commercial-Free !!!
 
Odgovor na temu

spartak

Član broj: 5625
Poruke: 631
*.yubc.net



+3 Profil

icon Re: ASP.NET forma - fokus na kontrolu02.03.2004. u 10:10 - pre 244 meseci
Probaj Page.SmartNavigation property. Primera radi:

Code:
<%@ Page attribute="value" [attribute="value"…] %>


Code:
<%@ Page .... SmartNavigation="true" %>


Ovo bi trebalo posle postback da te vrati tacno odakle si ga poslao.
 
Odgovor na temu

Simke
Marko Simic
Sandfield Associates (Solution
Developer)
Novi Zeland

Član broj: 1158
Poruke: 751
*.avenue.co.nz

ICQ: 71578686
Sajt: www.sandfield.co.nz


Profil

icon Re: ASP.NET forma - fokus na kontrolu03.03.2004. u 01:25 - pre 244 meseci
Hvala na odgovorima, Page.SmartNavigation je resilo problem.
All beer is good. Some beer is better.
 
Odgovor na temu

[es] :: .NET :: ASP.NET :: ASP.NET forma - fokus na kontrolu

[ Pregleda: 2697 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.