Showing posts with label situation. Show all posts
Showing posts with label situation. Show all posts

Wednesday, March 28, 2012

LinkButton/DataGrid/HoverMenu Issue - Linkbutton not passing values?

Hello all,
I have a unique situation here, that I have been stumped on for 3 days now. I have a nested master/detail form as seen below, and within the 2nd grid I have an AJAX hovermenu, for some reason I am not able to collect the values of the form when the user wants to insert the values. I am able to capture the linkbutton event in the code behind but, when it gets to the assigning of the textbox value for entry into the DB it is comes up with a reference not set to the instance of an object. The first set of code is the asp.net page the second set is the code behind, any pointers on this would be extremely helpful, and I would owe you like lunch or something :) Thanks again for all of your help.

ASP.Net Code

1<asp:UpdatePanel ID="up0" runat="server" Visible="true">2 <ContentTemplate>3 <asp:GridView4 ID="GridView1"5 runat="server"6 Width="656px"7 CellPadding="4"8 DataSourceID="SqlDataSource1"9 ForeColor="#333333"10 OnRowDataBound="bindMarketControl"11 AutoGenerateColumns="False"12 GridLines="None"13 >14 <Columns>15 <asp:TemplateField>16 <ItemTemplate>17 <h2><%# Eval("MarketName")%></h2>18 <table width="100%">19 <tr>20 <td width="200px">Team Name</td>21 <td width="200px">Head Count</td>22 <td width="200px">Orders</td>23 <td width="200px">Revenue</td>24 </tr>25 </table>26 <asp:UpdatePanel ID="up1" runat="server">27 <ContentTemplate>28 <asp:GridView29 ID="TeamDetail"30 DataSourceID="GetTeamDetailFormView"31 AutoGenerateColumns="False"32 ShowHeader="False"33 GridLines="None"34 runat="server">35 <Columns>36 <asp:TemplateField>3738 <ItemTemplate>39 <asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">40 <div style="border:1px outset white;padding:2px;">41 <div><asp:LinkButton42 ID="LinkButton1"43 runat="server"44 CommandName="Edit"45 Text="Edit"46 /></div>47 <div><asp:LinkButton48 ID="LinkButton2"49 runat="server"50 CommandName="Delete"51 Text="Delete" /></div>52 </div>53 </asp:Panel>54 <asp:Panel ID="Panel9" runat="server">55 <table width="100%">56 <tr>57 <td width="195px">58 <asp:Label59 Font-Bold="true"60 ID="Label0"61 runat="server"62 Text='<%# Eval("TeamName")%>' />63 </td>64 <td width="200px">65 <asp:Label66 ID="Label1"67 runat="server"68 Text='<%# Eval("HeadCount")%>' />69 </td>70 <td width="200px">71 <asp:Label72 ID="Label2"73 runat="server"74 Text='<%# Eval("Orders")%>' />75 </td>76 <td width="200px">77 <asp:Label78 ID="Label3"79 runat="server"80 Text='<%# Eval("Revenue")%>' />81 </td>82 </tr>83 </table>84 </asp:Panel>85 <cc1:HoverMenuExtender ID="hme2"86 HoverCssClass="popupHover"87 PopupControlID="PopupMenu"88 PopupPosition="Left"89 TargetControlID="Panel9"90 PopDelay="25"91 runat="server" />92 </ItemTemplate>93 <EditItemTemplate>94 <asp:Panel ID="Panel9" runat="server" Width="100%">95 <table width="100%">96 <tr>97 <td width="200px">98 <asp:TextBox99 ID="TextBox00"100 runat="server"101 Text='<%# Bind("TeamId")%>'102 Visible="false"103 EnableViewState="true"104 />105 <asp:TextBox106 ReadOnly="true"107 Font-Bold="true"108 ID="TextBox0"109 runat="server"110 Text='<%# Bind("TeamName")%>'111 EnableViewState="true" />112 </td>113 <td width="200px">114 <asp:TextBox115 ID="TextBox1"116 runat="server"117 Text='<%# Bind("HeadCount")%>'118 EnableViewState="true" />119 </td>120 <td width="200px">121 <asp:TextBox122 ID="TextBox2"123 runat="server"124 Text='<%# Bind("Orders")%>'125 EnableViewState="true"126 />127 </td>128 <td width="200px">129 <asp:TextBox130 ID="TextBox3"131 runat="server"132 Text='<%# Bind("Revenue")%>'133 EnableViewState="true" />134 </td>135 </tr>136 </table>137 </asp:Panel>138 <cc1:HoverMenuExtender139 ID="hme1"140 TargetControlID="Panel9"141 PopupControlID="PopupMenu"142 HoverCssClass="popupHover"143 PopupPosition="Right"144 runat="server">145 </cc1:HoverMenuExtender>146 <asp:Panel ID="PopupMenu" runat="server" CssClass="popupMenu">147 <div style="border:1px outset white">148 <div>149 <asp:LinkButton150 ID="lbtnInsertUpdate"151 runat="server"152 CausesValidation="True"153 CommandName="Insert"154 Text="Insert"155 OnClick="lbtnInsertUpdate_Click"156 />157 </div>158 <div>159 <asp:LinkButton160 ID="LinkButton2"161 runat="server"162 CausesValidation="False"163 CommandName="Cancel"164 Text="Cancel" /></div>165 </div>166 </asp:Panel>167 </EditItemTemplate>168 </asp:TemplateField>169 </Columns>170 </asp:GridView>171 </ContentTemplate>172 </asp:UpdatePanel>173 <asp:SqlDataSource174 ID="GetTeamDetailFormView"175 runat="server"176 ConnectionString="<%$ ConnectionStrings:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX%>"177 SelectCommand="sp_GetTeamDetails"178 SelectCommandType="StoredProcedure"179 InsertCommand="sp_InsertDataInfo"180 InsertCommandType="StoredProcedure">181 <SelectParameters>182 <asp:Parameter Name="MarketID" />183 <asp:ControlParameter184 ControlID="ddlVPInfo"185 DefaultValue=""186 Name="vpid"187 PropertyName="SelectedValue"188 Type="Int32" />189 </SelectParameters>190 <InsertParameters>191 <asp:Parameter Name="TeamID" />192 <asp:Parameter Name="HeadCount" />193 <asp:Parameter Name="Orders" />194 <asp:Parameter Name="Revenue" />195 <asp:ControlParameter196 ControlID="tbEntryDat"197 Name="DataDate"198 PropertyName="Text"199 Type="String" />200 </InsertParameters>201 </asp:SqlDataSource>202 <hr />203 </ItemTemplate>204 </asp:TemplateField>205 </Columns>206 </asp:GridView>207208 <asp:SqlDataSource209 ID="SqlDataSource1"210 runat="server"211 ConnectionString="<%$ ConnectionStrings:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX%>"212 SelectCommand="sp_GetMarketCats"213 SelectCommandType="StoredProcedure">214 <SelectParameters>215 <asp:ControlParameter216 ControlID="ddlVPInfo"217 DefaultValue=""218 Name="vpid"219 PropertyName="SelectedValue"220 Type="Int32" />221 </SelectParameters>222 </asp:SqlDataSource>223224 </ContentTemplate>225 <Triggers>226 <asp:AsyncPostBackTrigger227 ControlID="btnDisplayEntry"228 EventName="Click" />229 </Triggers>230 </asp:UpdatePanel>

The Code Behind

1Protected Sub lbtnInsertUpdate_Click(ByVal senderAs Object,ByVal eAs EventArgs)2Dim TeamInfoDBConnAs New SqlConnection(ConfigurationManager.ConnectionStrings("XXXXXXXXXXXXXXXXX").ConnectionString)3Dim sqlStringAs String ="sp_InsertDataInfo"4Dim sqlCmdAs New SqlCommand(sqlString, TeamInfoDBConn)5 sqlCmd.CommandType = CommandType.StoredProcedure67'Dim NewText As String =8 'Dim val1 As TextBox = CType(e.Item.FindControl("TextBox3"), TextBox)9 'MsgBox(val1.Text)101112 sqlCmd.Parameters.AddWithValue("@dotnet.itags.org.TeamID", TextBox00.Text)13 sqlCmd.Parameters.AddWithValue("@dotnet.itags.org.HeadCount", TextBox1.Text)14 sqlCmd.Parameters.AddWithValue("@dotnet.itags.org.Orders", TextBox2.Text)15 sqlCmd.Parameters.AddWithValue("@dotnet.itags.org.Revenue", TextBox3.Text)16 sqlCmd.Parameters.AddWithValue("@dotnet.itags.org.DataDate", tbEntryDate.Text)1718 TeamInfoDBConn.Open()19 sqlCmd.ExecuteNonQuery()20 TeamInfoDBConn.Close()21 sqlCmd =Nothing22 End Sub

Bump...Still looking for anyone that might have some idea about this one?? thank-you!

Wednesday, March 21, 2012

LoadScriptsBeforeUI and Web.config debug=true

I've searched around for an answer for this particular situation, but I haven't found a good answer. I'm hoping someone can explain what is going on.

The situation is that I have a very simple aspx page, containing an UpdatePanel. The UpdatePanel contains an Asynchronous Trigger, tied to a Timer, which is also within the UpdatePanel. The Script manager has various attributes, but the key things are that it has the attribute LoadScriptsBeforeUI = "False", and it also references a custom javascript file. That javascript file simply ties some alerts to the request events. I have included the source below.

The problem is that when the web.config has the compilation debug=true flag set, this page throws an error. Basically, when the timer executes, between the BeginRequest and EndRequest events, the following error appears:

Sys.InvalidOperationException: Type Sys.UI._Timer has already been registered

Basically, on the AJAX response, it's attempting to reregister the Timer type with the AJAX framework, via the RegisterClass() method in the AJAX framework. I've traced this back to the fact that when the debug is set to true in the web.config, the AJAX framework uses the debug version of the scripts, which throws this error. The production version of the AJAX scripts does not look for this error, nor does it care whether something has been registered twice.

Some other relevant facts:

a. Whether or not debug is set, if LoadScriptsBeforeUI is removed (or set to true), the re-registration error doesn't occur, but the custom javascript file is unable to complete, because the Sys object apparently doesn't exist when that custom javascript file starts running.

b. Whether or not debug is set, if LoadScriptsBeforeUI is removed (or set to true) AND the ScriptReference to the custom javascript file is removed, this re-registration error doesn't occur. The page works fine. Odd, because the error doesn't seem to reference the custom javascript file, it references the Timer.

c. Whether or not debug is set, if LoadScriptsBeforeUI is kept at false, AND the ScriptReference to the custom javascript file is removed, the re-registration error occurs. So, at a minimum, the problem is between the LoadScriptsBeforeUI=false and the behavior of the response.

So, boiled down, this is a very simple page. When the debug= true, AND the LoadScriptsBeforeUI=false it throws that strange error. What I need to know is:

1. Aside from the debug setting, why is the response trying to re-register the Timer object with the page? And why does it depend on the

2. On a side note, is there a way to set LoadScriptsBeforeUI =true (or leave it out), AND have the custom javascript file able to reference the Sys object?

3. Generally... what's up? I've tested this on a few machines, and it's all the same.

If I need to clarify some things, let me know. Below is the source:

===============================

UnitTest1.aspx

===============================

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeBehind="UnitTest1.aspx.cs" Inherits="Portal.UnitTest1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="PortalSM" runat="server" EnablePageMethods="True" EnableScriptGlobalization="True"
EnableScriptLocalization="True" LoadScriptsBeforeUI="False" EnablePartialRendering="true">
<Scripts>
<asp:ScriptReference Path="UnitTestJavascript.js" />
</Scripts>
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="Tick" />
</Triggers>

<ContentTemplate>

<asp:Timer ID="timer1" runat="server" Interval="1000"></asp:Timer>

<asp:Label runat="server" ID="time2"></asp:Label>

</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

===============================

UnitTest1.aspx.cs

===============================

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxControlToolkit;

namespace Portal
{
public partial class UnitTest1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(100);
string theTime = DateTime.Now.ToLongTimeString();
for (int i = 0; i < 3; i++)
{
theTime += "<br />" + theTime;
}
time2.Text = theTime;
}
}
}

===============================

UnitTestJavascript.js

===============================


_fired1 = false;
_fired2 = false;
_fired3 = false;


Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequestHandler);


function InitializeRequestHandler(sender, args)
{
if (!_fired1)
alert("Initializerequest");

_fired1 = true;
}

function BeginRequestHandler(sender, args)
{
if (!_fired2)
alert("Beginrequest");

_fired2 = true;
}

function EndRequestHandler(sender, args)
{
if (!_fired3)
alert("Endrequest");

_fired3 = true;
}


if (typeof('Sys') !== 'undefined')
Sys.Application.notifyScriptLoaded();

I may have explained it too complicated, but it should be an easy question. Anyone know?


I'm looking into this... I'll let you know what I find shortly.


It's a confirmed bug that will be fixed in the next release. Basically, it has to do with how the PageRequestManager detects which scripts have already been loaded on the page. With LoadScriptsBeforeUI=true, the URLs match, with LoadScriptsBeforeUI=false, they differ by an encoded ampersand (& != &), so the script attempts to load a 2nd time.

Do you have to use LoadScriptsBeforeUI=false, or is true acceptable as a workaround in the meantime? If you need a workaround that enables LoadScriptsBeforeUI=false let me know.



Thanks, that's great information. When you say next release, is the next release going to be an AJAX-only release version, or the full .NET framework with AJAX bundled in (3.1, 3.5, or whatever)?

The only reason I have to use LoadScriptsBeforeUI = false, is because the custom javascript file (UnitTestJavascript.js) is attempting to attach events to the Sys object (as shown above). If LoadScriptsBeforeUI = true, then the Sys object doesn't exist when the custom javascript is being run, and those event attachments throw an error about Sys not being an object.

So, I guess the next question would be:

How can I ensure that the Sys object is available for use in my custom javascript file (UnitTestJavascript.js), without delaying it to the end by using LoadScriptsBeforeUI? If there's a way to make the custom script wait somehow, that would be good.

This behavior is somewhat unexpected, because I more or less assumed that the custom javascript file would not be loaded until the rest of the true AJAX code had been executed, and the sys objects existed.

Again, thanks!


Just put your JavaScript after the ScriptManager tag.


Hi,

are you referencing the custom file through the ScriptManager control?


If you are using any Custom Javascript file then use ScriptManager to load the JS file like the following:

<asp:ScriptManager ID="TheScriptManager" runat="server">
<Services>
<asp:ServiceReference Path="~/DataService.asmx" />
</Services>
<Scripts>
<asp:ScriptReference Path="~/YOUR JS FILE" />
</Scripts>
</asp:ScriptManager>

Or If you have javascript embedded in Aspx page then add it after the ScriptManager, like following:

<asp:ScriptManager ID="TheScriptManager" runat="server"></asp:ScriptManager>
<script type="text/javascript">
//YOUR JS CODES
</script>


I don't think the problem is that Sys is not defined, its that PageRequestManager.getInstance is returning null. You are attempting to use the request manager before its been initialized. The ajax framework is always loaded first, so Sys should definitely be there. Just define an application init event and add your request manager events from there --

Sys.Application.add_init(function() { /* add request manager events here */ } );


Hi you can use external javascript file with scriptmanager like this Smile

<asp:ScriptManager ID="TheScriptManager" runat="server">
<Scripts>
<asp:ScriptReference Path="~/YOUR JS FILE" />
</Scripts>
</asp:ScriptManager>


Ah, great idea. Again, thanks for the information. Knowing that was a known bug was very helpful.

Thanks!