Posted by Ricibald on 22nd July 2011
It’s very useful to express everything in JQuery instead of ASP.NET AJAX events system: in this way we can use a lot of useful JQuery controls.
To achieve this just add this snippet of javascript code:
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequest);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
function BeginRequest(sender, args) {
jQuery.event.trigger('ajaxSend');
}
function EndRequest(sender, args) {
jQuery.event.trigger('ajaxComplete');
}
</script>
In this way you can capture standard JQuery event to obtain for example a modal progress feedback both in case of JQuery ajax POST and in case of ASP.NET UpdatePanel events:
<script type="text/javascript">
$(document).bind("ajaxSend", function () {
$("#loadingAjax").dialog({ modal: true });
}).bind("ajaxComplete", function () {
$("#loadingAjax").dialog("close");
});
</script>
Posted in asp.net, javascript, jQuery | No Comments »
Posted by Ricibald on 19th April 2011
jQuery allows only to do a global form submit using
$("form").submit()
This method doesn’t allow to do a specific form submit when multiple <input type=”submit”> exists, like in many ASP.NET sites, where there are a single form with many buttons.
To achieve this and obtain an ASP.NET POSTBACK behavior simply use this snippet of jQuery code that builds a “submit simulation from input”:
// simulate submit from button "myButton"
var input = $("<input>").attr("type", "hidden").attr("name", $('#myButton').attr("name")).val("");
$('form').append($(input));
$('form').submit();
Posted in .net, javascript, jQuery | No Comments »
Posted by Ricibald on 6th February 2009
Il problema è questo: devo creare un LinkButton che sia sempre Enabled. Ma se un suo contenitore (ad esempio un Panel) è disabilitato, allora il LinkButton nel rendering va ad impostare la proprietà disabled navigando tra i padri.
Sarebbe bello se riuscissimo a modificare il comportamento dei WebControl per non rilevare disabled in uno dei padri. La soluzione sta nell’impedire che il nostro controllo figlio (ad esempio il nostro LinkButton) faccia uso di alcune funzionalità ereditate dalla classe base WebControl.
Ricerche su Internet non sono servite. Ho cercato come è implementato il WebControl ispezionando il codice sorgente di WebControl di Mono e il codice sorgente di LinkButton.
Il risultato è di seguito:
public class LinkButtonSmartAlwaysEnabled : LinkButton
{
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
//base.AddAttributesToRender(writer);
if (ID != null)
writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
if (AccessKey != string.Empty)
writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, AccessKey);
//if (!enabled)
// writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
if (ToolTip != string.Empty)
writer.AddAttribute(HtmlTextWriterAttribute.Title, ToolTip);
if (TabIndex != 0)
writer.AddAttribute(HtmlTextWriterAttribute.Tabindex, TabIndex.ToString());
if (Enabled && Page != null)
{
string href = Page.ClientScript.GetPostBackClientHyperlink(this, "");
writer.AddAttribute(HtmlTextWriterAttribute.Href, href);
}
if (this.Attributes != null)
foreach (string s in this.Attributes.Keys)
writer.AddAttribute(s, this.Attributes[s]);
}
}
Posted in .net | No Comments »