Showing posts with label select. Show all posts
Showing posts with label select. Show all posts

Saturday, March 24, 2012

Exception has been thrown by the target of an invocation

I have a scriptmanager and updatepanel, inside the panel is a gridview it's bound to an objectdatasource, when I click the select button in the grid I get the alert with the message "Exception has been thrown by the target invocation". How would I know the source of this error, or what is causing the error. Is there a way to get the real exception that occurred not just a message?

Thanks

Disable the ajax for a moment (EnablePartialRendering="false" on the scriptmanager).
This error message is about as useful as a chocolate fireguard. Disabling the update panel is fine for development, and the few bugs that I stumble across while developing. But what about in a production situation. If I get my clients phoning up telling me the app won't work becuase an "Exception has been thrown by the target of an invocation", then I'll just explain to them how to disable AJAX so I can get a useful error message. AHH. No. I don't think so. Is there some way that you can actually pass the message text up to the popup box. Dev's like me are pretty reliant on the exception text. Especially as we often just write stuff and then it gets put into production without rigourous testing. Not ideal, but thats what happens in the real world outside of Redmond.

Was this resolved at all? I have a similar issue:

Steps to Reproduce

1) I have a DB table with a column which is varchar(1024)

2) I want this column to only contain unique strings

3) So I add a trigger to the column to check for the data entered and use RaisError if any problems

4) I setup my Datagrid/ObjectDataSource/BLL/DAL and all works fine in aspx, the page errors with the correct message.

5) I add in an AJAX Update Panel and *it* (the ASP.NET AJAX Libraries) just spits out a JSON string containing an alert message "An exception occured by the the target of an invocation". THAT is not the correct error string.

Why is it not? and how do I alter this behaviour to make it send a JSON string containing the correct Error message?

Thank


Was this resolved at all? I have a similar issue:

Steps to Reproduce

1) I have a DB table with a column which is varchar(1024)

2) I want this column to only contain unique strings

3) So I add a trigger to the column to check for the data entered and use RaisError if any problems

4) I setup my Datagrid/ObjectDataSource/BLL/DAL and all works fine in aspx, the page errors with the correct message.

5) I add in an AJAX Update Panel and *it* (the ASP.NET AJAX Libraries) just spits out a JSON string containing an alert message "An exception occured by the the target of an invocation". THAT is not the correct error string.

Why is it not? and how do I alter this behaviour to make it send a JSON string containing the correct Error message?

Thank you

Wednesday, March 21, 2012

event with AutoComplete Extender

IS there an event that fires when you select a text from an autocomplete extender? i am also getting the values from a database and is there a way to get the a corresponding value into another control(like into an hidden field, that would be really helpful).

Thank you

Hi ,

Please refer to this thread

autocomplete key value pair

Hope this helps


Hi Doulcat,

Here is the example

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TBSearch" runat="server"></asp:TextBox>
<asp:Panel runat="server" ID="myPanel" Height="100px" ScrollBars="Vertical">
</asp:Panel>
<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1"BehaviorID="myACEBID"TargetControlID="TBSearch"
ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList" MinimumPrefixLength="1"
CompletionInterval="1" EnableCaching="true" CompletionSetCount="12" CompletionListElementID="myPanel" />
<script type="text/javascript" language="javascript">
function pageLoad(){
$find("myACEBID").add_itemSelected(onItemSelected);
}
function onItemSelected(){
//add your javascript here
}
</script>

</form>

Hope this help.

Best regards,

Jonathan


Thank you for your help, it is helpful and i guess close to working(i am getting some results, but it is generating another error.)

I guess i will start another post for the new error. Thank you


What's your error Doulcat? I think that we're working on the same problem.

Also, can you please provide the javascript to pass the entered value of the textbox to a control parameter?


Sure the error i was getting was an exception: httprequest unhandled, and the inner exception was An extender can not be register before being prerender. All i had to do was called base.onprerender(e) where the page onprerender was overriden.

Sure for the javascript: i used

<scriptlanguage="javascript"type="text/javascript">

function IAmSelected( source, eventArgs ) {

alert("KEY: "+eventArgs.get_text());

window.location = "www.somesite.com/page="+eventArgs.get_value();

}

this is my extender

<cc1:AutoCompleteExtenderID="AutoCompleteExtender1"runat="server"CompletionInterval="500"

CompletionSetCount="5"MinimumPrefixLength="1"ServiceMethod="GetCompletionList"

TargetControlID="TextBox1"UseKeyValuePairs="True"OnClientItemSelected="IAmSelected">

</cc1:AutoCompleteExtender>

hope it helps. if not let me know, i have been struggling so much with it maybe i can.


I couldnt get it to work. i think that it has to do with my web service. It looks like you followed the earlier posts. I used the other guys suggestion and it seems to be working up until now. Can you please show me your web service? I need to see where to insert that first line. See right now I just need to pass the text box value to a control parameter to populate a dataview. I am trying to get away from the AutoPostBack in the textbox because it kills the web service after that.

Thanx

Cesar


I actually didn't use the web service, i couldn't get it to work(for some reason, the only difference with c# was that it wasn't static) But i did use the method in the page behind, here you go:

<Services.WebMethod()> _

<Script.Services.ScriptMethod()> _

PublicFunction GetCompletionList(ByVal prefixTextAsString,ByVal countAsInteger)AsString()

Dim sqlAsString ="Your select string + where x=@.prefixText"

Dim daAs System.Data.SqlClient.SqlDataAdapter =New System.Data.SqlClient.SqlDataAdapter(sql,"Your connection string")

da.SelectCommand.Parameters.Add("@.prefixText", System.Data.SqlDbType.VarChar, 50).Value ="%" + prefixText +"%"

Dim dtAs System.Data.DataTable =New System.Data.DataTable()

da.Fill(dt)

Dim itemsAs Collections.Generic.List(OfString) =New Collections.Generic.List(OfString)(dt.Rows.Count)Dim drAs System.Data.DataRow

ForEach drIn dt.Rows

items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateKeyValuePair(dr("text").ToString, dr("value").ToString))

Next

Return items.ToArray()

EndFunction

Text and value should be the name of the columns you get from the select string. the javascrip should be placed in the markup. I think the way to access a control is something like:

<scriptlanguage="javascript"type="text/javascript">

function IAmSelected( source, eventArgs ) {

alert(" Key : "+ eventArgs.get_text());

alert ("Clearing message field");

document.forms[0].elements["TextBox1"].value ='eventArgs.get_text()';

}

</script>


Hmmm...no luck. I'll keep at it.


Hi Doulcat,

Have you opened another post yet? Please provide as more as possible information in the new tread. We will discuss it on your new tread. Thanks

Best regards,

Jonathan


Hi Jonathan

i did open a new tread:http://forums.asp.net/t/1164269.aspx

Thanks for everything, i actually have it working. Now i am looking to improve on the displaying of the control. Any suggestions would be greatly appreciated. Thanks