.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

SPUtility.TransferToErrorPage("My Message") not allowed to attach any controls event.

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :SharePoint
Hi, I have created a custom error page and update it using to webApplication using following code: WebApplication.UpdateMappedPage(SPWebApplicaton.SPCustomPage.Error, CustomErrorPage) My error page contains one link button and onClick event, I have to perform some operations. As I click on the button Error is occurred and onClick event code didn't execute. If I render custom error page by providing url in IE like http://myweburl/_layouts/myerrorpage then every thing is working fine i.e. every event is working fine. Also If I use SPUtility.Redirect() method instead of SPUtility.TransferToErrorPage() then also every thing is working fine. My error message is as follow in case of SPUtility.TransferToErrorPage(): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. StackTrace is [HttpException (0x80004005): Unable to validate data.]    System.Web.Configuration.MachineKeySection.GetDecodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Int32& dataLength) +10988853    System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +295 [ViewStateException: Invalid viewstate. Client IP: fe80::8960:150e:cf5d:2e17%11 Port: 53192 User-Agent: Mozill

View Complete Post

More Related Resource Links

Adding client event handlers to an ASP.NET controls programmatically



I want to add client event handlers to ASP.NET controls (For example: GridView/Button ) programmatically to ASP.NET.

I am aware of "onclick" event handler, so my code would be

GridView1.Attributes.Add("onclick", "JSGridViewFunction()");

Button1.Attributes.Add("onclick", "JSButtonFunction()");

I want to know what are all the event handlers that are available for (or that can be added to)  ASP.NET controls.

For example, I want to add "onsort" event handler to ASP.NET GridView control.

But the following code fails

GridView1.Attributes.Add("onsort", "JSGridViewFunction()");

Please help.


Generated controls - skipping focus event - C# + JS


Ok, here is my senario.

A random (6-15) amount of textboxes are generated. Each textbox represents only one character. From those textboxes, three of them (at a random position) are enabled and the rest disabled.


When I put a character in any enabled textbox, it must put the focus on the next enabled textbox.


Textbox IDs go from 'char0' to 'char15' OR 'char0' to 'char12' OR ...

All the textboxes are generated so I can't set up specific focus events for each textbox because the designated control is unknown at design time.

Here is my attempt:


<script type="text/javascript">
    function abc(nextfocus)


for (int i = 0; i < focusableControls.Length-1; i++)
focusableControls[i].ClientSideEvents.KeyDown = "abc(" + focusableControls[i + 1].ID + ")";


focusableControls is an array with all the textboxes in that can get focus. It is also in the right order.

Things I want to find out:

How will I send the textbox out of focus

SPUtility.TransferToErrorPage(message) System.Thread.Abort


In a web part, i create a new site and add some items to the list of the neew site.

Then i redirect to the site.

If there is any error i use the SPUtility.TransferToErrorPage(message) but there is an error System.Thread.Abort.


I was googling and found that if there is any code running, this error should appears.

Any solution for this problem? any other function?


TextBox in UserControl: "TextChanged" event does not see other controls


I am building a UserControl with several TextBox controls. The behavior I'm looking for, is everytime a value is changed in any TextBox, the UserControl refreshes a couple labels contained within it. Here's the code behind file that does the work:

Public Sub Refresh(ByVal sender As Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
    lblTotalHours.Content = txtHours.Text
End Sub

Now, here's a way to hook it up that works, however, "PreviewTextInput" gives the old textbox value to Refresh() and not the new one (as expected). I'm just writing this example because I had to confirm that my method of linking the event worked - and it does. My application runs fine even though the result isn't what I am looking for: (edit: to make it work, i also adapted the Refresh() declaration to match the PreviewTextInput delegate to TextCompositionEventArgs, if I recall correctly...)

<UserControl ...>
        <Style TargetType="x:Key TextBox">
            <EventSetter Event="PreviewTextInput" Handler="Refresh" />
        <TextBox Name=&q

Only Content controls are allowed directly in a content page that contains Content controls


Hello Everyone,

  I am getting this error "Only Content controls are allowed directly in a content page that contains Content controls". I am using a single aspx page and not a separate cs file. Now, to write code inside aspx page, I am using <script> tag. Now, my problem is inside one of the method I have to use <script> tag. Now, when i use that this error comes. Eg

  <script runat="server">

 ........inside it coding done

  // Method inside which I have to use this tag again

  public void abc()


........initially some code.........

Response.Write("<script>document.getElementById('PaylForm').submit();</script></body></html>");   //This gives error




Thanks in Advance.

How to disable the controls within the JQGrid on some other event



I am trying to disable the controls within the JQGrid on some other event. Please let me know how can i do this. Below is my JQGrid Basically i want to disable the custom buttons btnDeleteExistingRoles, btnAddExistingRoles and the checkboxes that are created in the "Select" column( i have written a custom formatter for this). Please help

jQuery(document).ready(function() {

    $('#btnHdnExistingRoles').click(function() {
        var lastsel2;
        jQuery("#grdExistingRoles").jqGrid({ url: '/SAPWebAccess/Role.mvc/GetExistingRoleForUser/',
            datatype: 'json', mtype: 'GET',
            colNames: ['Role ID', "<input type='checkbox' id = 'headerCheck' onclick='checkAll(\"grdExistingRole\");'>", 'Role Name', 'Role Text', 'Valid From'

How to create event handlers for Composite Controls



How to create event handlers for Composite Controls. I have created a composite control with label, textbox and button. Like this

        public TextBox txt1 = new TextBox();
        public Label lbl1 = new Label();
        public Button btn1 = new Button();

protected override void CreateChildControls()



Now how to write the code once a event fires like text changed or click.



ASP.NET validation controls are removing client event handlers.


 Below is a tiny section of code to highlight a problem that I am currently having. The textbox has an onblur event (the workings of the onblur event are irrelevant), and an associated RequiredFieldValidator. This code functions exactly as it should. However, if in the body onload event I simply raise an alert of the innerHTML of tr1 or td1, the onblur event does not appear (but it does work, and can be seen when I view source in IE7). If I remove the RequiredFieldValidator, the onblur event handler is shown in the alert, or if I retain the validator but change onblur to onfocus, then the event handler also appears in the alert. I need this to work as when the user increases the Quantity, duplicates of the table row are added (I have tried both cloneNode, and setting the innerHTML of each new table cell to that of the original, but as my alert proves, the onblur event handler is not included in what is copied). The same problem also occurs with onchange for select tags with validators. I am using Visual Studio 2008 (.Net 2), IE7 and IIS 7.

<tr id="tr1" /> 
  <td id="td1" />Quantity <input id="txtQuantity" onblur="fnBlur(this)" type="text" maxlength="2" value="1" runat="server" />   
 <asp:RequiredFieldValidator id="reqQuantity"

Button onclick event not firing when some AJAX controls are introduced



I have a web page which has both asp.net controls as well as AJAX controls.I am facing a weird issue when I introduce some AJAX controls(Modal popup) inside a tabbed panel, the button onClick event stops firing.Can anyone suggest what might be the reason for this?

Here is my code:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Entity.aspx.cs" Inherits="Entity" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="HeaderImagePlaceHolder" Runat="Server">
<img src="images/image5.jpg" alt="NewsPageImage" />
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager_TabContainer" runat="server">
      <asp:TabContainer ID="TabContainer_Metadata" runat=&q

Dynamic hyperlink controls in button click event


Hi, i am creating a visual webpart in which when button is clicked dynamically hyperlinks must be displayed

In my senario i am having textbox,button,repeater control,when i enter url in textbox and click the button,hyperlink must be dynamically created and displayed in repeater control

i am not able to do this

thank you


Event bubbling - Mousehover event for child controls



I have a form and some controls inside it.

I want to fire an event when user enter the form and when he leaves the form .

this.MouseEnter += (sender, e) =>
   //do stuff

this.MouseLeave += (sender, e) =>
   //do stuff

the problem with that is when I move mouse over the child control, form's mouseleave event is triggered.

I don't want this to happen (even if the mouse over control is still over the form).


How to solve that?

I don't want to set any events on the children (because there are many controls and some of them create dynamically).

I also don't want to use any timers to check the position....

I know I can use IMessageFilter, and add to application:

 Application.AddMessageFilter(new MyMessageFilter());
 public bool PreFilterMessage(ref Message m)
if (m.Msg == 0x2a1) { }
But this will fire for entire application and not just for one form, and I don;t know how to detect inside PreFilterMessage the current control.



bind event handler for dynamic controls in repeater



I am faceing following problem


I have a repeater control on a modal popup extender. On run time I add linkbutton based on the number of items in a datatable assigned to that repeater control.In itemDataBound event of repeater I am adding that link button, like this


if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                LinkButton lbtn = new LinkButton();
                lbtn.ID = "lbtn" + DataBinder.Eval(e.Item.DataItem, "DatasourceId").ToString();
                lbtn.Text = DataBinder.Eval(e.Item.DataItem, "DatasourceName").ToString();

                lbtn.Click += new EventHandler(lbtn_Click);



but this linkbutton event is not getting fired on click. only the modal popup goes off.

I tried with command also for linkbutton instead of Click event handler. But that also did not help.


Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

Custom Controls in C# .NET

Embedding user controls in a Windows form is just like adding a simple button or text box that are already provided with .NET. These basic controls were written essentially like you code your own controls. Typically the controls you design are to be used in multiple forms or to modularize your code. These reasons help reduce the amount of code you have to type as well as make it easier for you to change your implementation. There should almost never be any reason to duplicate code because it leaves a lot of room for bugs. So, implementing functionality specific to your control in the control's source code is a good idea. This reduces code duplication as well as modularize your code, which is a good programming guideline.

Accessing the different controls inside a GridView control

how we can access a particular control which resides inside a GridView control. In this article I will show you how you can access different controls inside a GridView control. We will see how we can access a TextBox control, a DropDownList control and a ListBox control. If you are working with ASP.NET 1.X then you might want to check out my article Accessing Different Controls Inside a DataGrid.

Using ASP.NET 3.5's ListView and DataPager Controls: Displaying Data with the ListView

Prior to ASP.NET 3.5, developers who needed to display a set of records could choose between the GridView, DataList, and Repeater controls. The GridView provides rich data features, but has a very boxy layout; the DataList and Repeater allow for a more flexible layout, but lack the "point and click" data features found in the GridView, DetailsView, and FormView controls. The ListView bridges the gap between layout flexibility and built-in data features.

This article, the first in a series of articles on the ListView and DataPager controls, looks at the ListView's many available templates and illustrates how to display data. Read on to learn more!

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend