I'm not using very ofter a web resources, so every time I need to use it, I'm wasting my time to google how to do it.
To save my time next time, a little example.
Set the Build Action on the js file to Embedded Resource and add few lines in:
AssemblyInfo:
[assembly: System.Web.UI.WebResource("path.to.my.javascript.file.js", "text/javascript")]
and in the custom web control:
protected override void OnPreRender(EventArgs e)
{
ClientScriptManager cs = this.Page.ClientScript;
cs.RegisterClientScriptResource(typeof(MyCustomControl), "path.to.my.javascript.file.js");
}
Thanks to these two lines in the OnPreRender event, the js script is loading from embedded resources into the page by WebResource.axd http handler. More detailed article can be found here.
Yesterday I was looking for an out of the box feature to place one big table on more than one page without the need to cut this table manually. I've found a very easy to use solution with longtable package.
Sample code:
\usepackage{longtable}
\begin{longtable}{|c|c|c|c|c|c|c|c|c|c|}
\caption{some fancy caption}
\label{tab:mylabel}
\tabularnewline
\hline
Iteration & 1 & 2 & 3 & 4 & 5 & 6 \tabularnewline \hline
DataSet & &&&&&\\\hline
Makao & 77,30 & 76,53 & 81,16 & 76,92 & 66,67 & 100 \tabularnewline \hline
& 75,17 & 75,72 & 69,23 & 75 & 100 & \tabularnewline \hline
& 98,30 & 77,27 & 80 & 100 &&\\\hline
& 98,07 & 88 & 66,67 & 100 &&\\\hline
& 98,23 & 100 &&&&\\\hline
& 75,17 & 75,70 & 69,23 & 75 & 100 &\\\hline
% more lines here..
\end{longtable}
If you have used normal tables in latex, you can see there are some differents. E.g. there is no \begin{table} tag and the \begin{tabular} is replaced with \begin{longtable}.
Documentation to longtable package is located here
I had recently a very interesting problem. I have a single button on my page, which opens a jquery ui dialog with other page containing single textbox control. After pressing the Ok button, using web service the textbox value is sending to the server and a label control on the main page is updating and the update panel containing this label is refreshing. Vary simple solution. Maybe too simple, because I have lost a few hours to investigate, why after pressing the Ok button, full postback occurs and after reload, the page containing the textbox control is loaded not the main page.
First let's look at the code:
main page:
<asp:content contentplaceholderid="MainContent" runat="server" id="BodyContent">
<asp:button text="Button" runat="server" id="Button1"></asp:button>
<asp:scriptmanager runat="server" id="ScriptManager1">
</asp:scriptmanager>
<asp:updatepanel runat="server" childrenastriggers="true" updatemode="Conditional"
id="UpdatePanel1">
<contenttemplate>
<asp:label text="Label" runat="server" id="Label1">
</asp:label>
</contenttemplate>
</asp:updatepanel>
<div id="container"> </div> <script type="text/javascript">
$('#MainContent_Button1').bind('click', function ()
{
$('#container').load('WebForm1.aspx', function ()
{
$(this).dialog({
"modal": true,
"width": 200,
"height": 100,
"resizable": true,
"buttons": {
"Ok": function ()
{
var t = $('#TextBox1').val();
$.ajax({
url: 'WebService1.asmx/GetValue',
data: "text=" + t,
type: 'POST',
success: function ()
{
__doPostBack('MainContent_UpdatePanel1', '')
}
});
$(this).dialog('destroy');
}
}
});
}); return false;
});
</script> </asp:content>
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
Label1.Text = Globals.Value;
}
}
}
public static class Globals
{
public static string Value { set; get; }
}
web service:
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public void GetValue(string text)
{
Globals.Value = text;
}
}
and the WebForm1:
<body>
<form id="form3" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Focus();
}
}
As you an see, nothing special.
So where is the problem in this code?
Everytime when I presssed the button, I drew attention that, in firebug together with my page are loading a web resources files containing stuff for the web forms:

Some time later I have found a __EVENTTARGET for that page. What is this? So this is a hidden field generated when e.g. some control has a AutoPostBack property set to true - www.dotnetspider.com/resources/189-AutoPostBack-What-How-works.aspx
It is using by __doPostBack function, which is responsile for refreshing the update panel. The problem is that, for the main page there is a __EVENTTARGET definied too.
As you can see in the listing, no one control has the AutoPostBack property.
So the only option was to find, what needed to have the possibility to change the textbox control on the WebForm1 page. In this example it's easy to tell that, it could be only the TextBox1.Focus() line in code behind file.
And really, after I commented this line, everything is working as I expected :)
If the focus is required, the jquery can do the work for us: $('#TextBox1').focus().