|
|
AspNet.sk > F�rum > .NET > Web Forms (ASP.NET)
Diskusné fórum
funa
12. 3. 2010 10:39:41
Príspevkov:
249
Článkov:
0
Blogy:
0
Správičiek:
0
Body:
1245
Najaktívnejší č.:
15
|
textbox + lostfocus
|
Caute.
Viem nejak odchytit asp:Textbox ... LostFocus, a priradit mu nejaku metodu v kode?
|
[Reakcia]
|
T
12. 3. 2010 11:18:54
Príspevkov:
1654
Článkov:
0
Blogy:
42
Správičiek:
162
Body:
13610
Najaktívnejší č.:
3
|
RE: textbox + lostfocus
|
@funa: bolo by treba doimplementovat do textboxu, nie je to tazke....trik je pridat onblur atribut do neho volanie __dopostback s tagetom samym controlom a po postbacku firenut zodpovedajuci event...vecer Ti to urobim, ak budem mat cas
Tomáš Zeman, MCSD.NET
|
[Reakcia]
|
T
13. 3. 2010 21:39:06
Príspevkov:
1654
Článkov:
0
Blogy:
42
Správičiek:
162
Body:
13610
Najaktívnejší č.:
3
|
RE: textbox + lostfocus
|
Ahoj, neviem ci je to este aktualne...ale paci... public class TextBox
: System.Web.UI.WebControls.TextBox
,IPostBackEventHandler
 ...{
public event EventHandler<EventArgs> Blur;

protected virtual void OnBlur(EventArgs args)
 ...{
if (Blur != null)
Blur(this, args);
}

protected override void AddAttributesToRender(HtmlTextWriter writer)
 ...{
base.AddAttributesToRender(writer);

if (AutoPostBack
&& Page != null
&& Page.Request.Browser.EcmaScriptVersion.Major >= 1)
 ...{
PostBackOptions options =
new PostBackOptions(this, "blur");
options.AutoPostBack = Page.Form != null;
options.PerformValidation = true;
options.ValidationGroup = ValidationGroup;

writer.AddAttribute("onblur",
Page
.ClientScript
.GetPostBackEventReference(options, true));
}
}

public void RaisePostBackEvent(string eventArgument)
 ...{
if (eventArgument == "blur")
OnBlur(new EventArgs());
}
} <my:TextBox runat="server" AutoPostBack="true" ID="MyTextBox" OnBlur="MyTextBox_Blur" />
Tomáš Zeman, MCSD.NET
|
[Reakcia]
|
funa
14. 3. 2010 13:36:47
Príspevkov:
249
Článkov:
0
Blogy:
0
Správičiek:
0
Body:
1245
Najaktívnejší č.:
15
|
RE: textbox + lostfocus
|
ok super.
diky moc.............
|
[Reakcia]
|
T
14. 3. 2010 16:04:10
Príspevkov:
1654
Článkov:
0
Blogy:
42
Správičiek:
162
Body:
13610
Najaktívnejší č.:
3
|
RE: textbox + lostfocus
|
@funa:
tu je fix, stale je tam problem, ze sa server side firene textchanged pred blurom, viem patchnut aj to, ale nie je to moc pekne :-D
public class TextBox
: System.Web.UI.WebControls.TextBox
,IPostBackEventHandler
 ...{
private const string
BLUR_DHMTL_EVENT = "onblur",
BLUR_CHANGE_EVENT = "onchange",
BLUR_EVENT_ARGS = "blur";

public event EventHandler<EventArgs> Blur;

protected virtual void OnBlur(EventArgs args)
 ...{
if (Blur != null)
Blur(this, args);
}

protected override void AddAttributesToRender(HtmlTextWriter writer)
 ...{
Page page = Page;
bool applyBlurEvent=
AutoPostBack
&& Blur != null
&& page != null
&& page.Form != null //error is thrown anyway
&& page.Request.Browser.EcmaScriptVersion.Major >= 1;

string currentBlurJS = String.Empty;
if (applyBlurEvent)
 ...{
string currentChangeJS = String.Empty;
if (HasAttributes)
 ...{
currentBlurJS = Attributes[BLUR_DHMTL_EVENT];
if (!String.IsNullOrEmpty(currentBlurJS))
 ...{
if (!currentBlurJS.EndsWith(";"))
currentBlurJS += ";";
Attributes.Remove(BLUR_DHMTL_EVENT);
}

currentChangeJS = Attributes[BLUR_DHMTL_EVENT];
if (!String.IsNullOrEmpty(currentChangeJS))
 ...{
if (!currentChangeJS.EndsWith(";"))
currentChangeJS += ";";
}

}
//ensure onchange won't postback
Attributes["onchange"]=
currentChangeJS + "return false;";
}

base.AddAttributesToRender(writer);

if(applyBlurEvent)
 ...{
PostBackOptions options =
new PostBackOptions(this, BLUR_EVENT_ARGS);
options.AutoPostBack = true;
options.PerformValidation = true;
options.ValidationGroup = ValidationGroup;

string blurJS = currentBlurJS
+ page
.ClientScript
.GetPostBackEventReference(options, true);

writer.AddAttribute(BLUR_DHMTL_EVENT, blurJS);
}
}

public void RaisePostBackEvent(string eventArgument)
 ...{
if (eventArgument == BLUR_EVENT_ARGS)
OnBlur(new EventArgs());
}

} Inak ten bazovy AddAttributesToRender je dost zly napisany :-(
Tomáš Zeman, MCSD.NET
|
[Reakcia]
|
T
14. 3. 2010 16:07:09
Príspevkov:
1654
Článkov:
0
Blogy:
42
Správičiek:
162
Body:
13610
Najaktívnejší č.:
3
|
RE: textbox + lostfocus
|
Mea culpa - mea maxima culpa :-))
public class TextBox
: System.Web.UI.WebControls.TextBox
,IPostBackEventHandler
 ...{
private const string
BLUR_DHMTL_EVENT = "onblur",
BLUR_CHANGE_EVENT = "onchange",
BLUR_EVENT_ARGS = "blur";

public event EventHandler<EventArgs> Blur;

protected virtual void OnBlur(EventArgs args)
 ...{
if (Blur != null)
Blur(this, args);
}

protected override void AddAttributesToRender(HtmlTextWriter writer)
 ...{
Page page = Page;
bool applyBlurEvent=
AutoPostBack
&& Blur != null
&& page != null
&& page.Form != null //error is thrown anyway
&& page.Request.Browser.EcmaScriptVersion.Major >= 1;

string currentBlurJS = String.Empty;
if (applyBlurEvent)
 ...{
string currentChangeJS = String.Empty;
if (HasAttributes)
 ...{
currentBlurJS = Attributes[BLUR_DHMTL_EVENT];
if (!String.IsNullOrEmpty(currentBlurJS))
 ...{
if (!currentBlurJS.EndsWith(";"))
currentBlurJS += ";";
Attributes.Remove(BLUR_DHMTL_EVENT);
}

currentChangeJS = Attributes[BLUR_CHANGE_EVENT];
if (!String.IsNullOrEmpty(currentChangeJS))
 ...{
if (!currentChangeJS.EndsWith(";"))
currentChangeJS += ";";
}

}
//ensure onchange won't postback
Attributes["onchange"]=
currentChangeJS + "return false;";
}

base.AddAttributesToRender(writer);

if(applyBlurEvent)
 ...{
PostBackOptions options =
new PostBackOptions(this, BLUR_EVENT_ARGS);
options.AutoPostBack = true;
options.PerformValidation = true;
options.ValidationGroup = ValidationGroup;

string blurJS = currentBlurJS
+ page
.ClientScript
.GetPostBackEventReference(options, true);

writer.AddAttribute(BLUR_DHMTL_EVENT, blurJS);
}
}

public void RaisePostBackEvent(string eventArgument)
 ...{
if (eventArgument == BLUR_EVENT_ARGS)
OnBlur(new EventArgs());
}

}
Tomáš Zeman, MCSD.NET
|
[Reakcia]
|
funa
15. 3. 2010 8:41:34
Príspevkov:
249
Článkov:
0
Blogy:
0
Správičiek:
0
Body:
1245
Najaktívnejší č.:
15
|
RE: textbox + lostfocus
|
No fajn.
Diky moc.
A za sa vola textchanged skor mi nevadi :)
|
[Reakcia]
|
|
|
|
|
|
|
|
|
|
Ak nie ste zaregistrovaný, prosím registrujte sa tu! |
|
|
|
Predmet: |
|
|
Text: |
Zdrojové / programové kódy vkladajte pomocou príkazu ! Takto vložený kód bude naformátovaný.
Kód je možné vložiť aj pomocou dvojice značiek [C#]Váš kód[/C#].
Namiesto C# je možné použiť následujúce značky: Assembly, Batch, C#, CSS, HTML, INI, Java, JScript, Lua, MSIL, Pascal, Perl, PHP, PowerShell, Python, SQL, VB.NET, VBScript, XAML, XML.
|
|
|
|
|
|
|