Advertisements

Archive

Archive for the ‘ASP.NET’ Category

UpdatePanel and triggers from a repeater control


If you want to backstop on some controls click you must need to specify triggers in UpdatePanel

For example:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
   <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
     <ItemTemplate>
       <%# Eval("Name") >%>
       <asp:Button ID="Button1" runat="server" Text="Button" />
      </ItemTemplate>
    </asp:Repeater>
 </ContentTemplate>
<Triggers>
   <asp:PostBackTrigger ControlID="Buton1" />
</Triggers>
</asp:UpdatePanel>

You will face following error message with above code

A control with ID ‘Button1’ could not be found for the trigger in UpdatePanel ‘UpdatePanel1’.

Here is simple solution for above problem

 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
  <ItemTemplate>
 <!--when cick the button1, it will fire the btnDummy-->
   <asp:Button ID="Button1" Text="Click"
   OnClientClick="$get('btnDummy').click();return false;"
   runat="server" />
  </ItemTemplate>
 </asp:Repeater>

 <!--Make a hidden button to treat as the postback trigger-->
 <asp:Button ID="btnDummy" runat="server" Style="display: none" Text="HiddenButton" />
Advertisements

Modify Collection while Iterating C#

May 10, 2017 1 comment

The general rule is that you can’t modify a collection/array/list while iterating over it.

If you are trying to modify loop while iterating you will get following error message

List strList = new List();

strList.Add(“1”);
strList.Add(“2”);
strList.Add(“3”);
strList.Add(“4”);

foreach(string str in strList)
{
strList.Add(“test”);
}

Error:

System.InvalidOperationException: Collection was modified; 
enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at Rextester.Program.Main(String[] args)

Here is the simple solution

int listLength = strList.Count();

for(int i=0; i<listLength; i++)
{

//Add New Element
if(i == 0)//Some codition when you want to add new element to list/array
{
listLength++;
strList.Add(“5”);
}

Console.WriteLine(strList[i]);
}

Hope it helps !

Send Email from a Static HTML

April 29, 2017 5 comments

Send an email without back-end/server side code.

There are many solutions available for sending an email here I am explaining steps to sending an email from html page using Google Apps mail.

1. Make a Copy of the Sample Spreadsheet.

Sample: https://docs.google.com/spreadsheets/d/1Bn4m6iA_Xch1zzhNvo_6CoQWqOAgwwkOWJKC-phHx2Q/

1

2.Open the Script Editor

Open the Script editor… by clicking “Tools” > “Script editor…

3

3. Set the TO_ADDRESS in the Script

4

4. Save a New Version of your Script

Goto File-> Manager Version option to set Version

5. Publish the Updated Script as a Web App

Goto menu Publish-> Deploy as Web app option to publish

Select the latest project version to deploy:

7

6. Authorize the Script to Send Emails

Click Continue to authorize this app

8

Copy the web app URL to your clip board / note pad. Then Click “OK”.

10

7. Create your basic HTML Form

11

8. Open the HTML Form (page) in your Browser

Fill in some sample data in the HTML Form:

12

Submit the form. You should see a confirmation that it was sent like

{“result”:”success”,”data”:”{\”color\”:[\”\”],\”name\”:[\”Rahul\”],\”message\”:[\”This is test \”],\”email\”:[\”rahulgbhatia@live.com\”]}”}

Alternate solution : Use Ajax to submit the form

Hope this help !

Background Reading

 

Set focus on textbox

November 16, 2016 Leave a comment

Using Jquery

$(function() {
  $("#Box1").focus();
});

Using Javascript
window.onload = function() {
  document.getElementById("Box1").focus();
};

HTML5 

http://www.codeproject.com/members/flair/8524963

Categories: ASP.NET, Code Project Tags: , , ,

Disable click outside of bootstrap model area to close modal


Problem :You can close the modal by clicking on the background. Is there anyway to disable this feature? On specific modals only?

Solution :

There is option called backdrop. Passing this option with value 'static' will prevent closing the modal.
Also can pass {keyboard: false} to prevent closing the modal by pressing Esc.

[1] If you opening the modal by js use:
$
('#myModal').modal({backdrop: 'static', keyboard: false})

[2] If you are using data attributes, use:
<button data-target="#myModal" data-toggle="modal" data-backdrop="static" data-keyboard="false">
    Launch demo modal
</button>`

 

 

HEX Color Code Converter / Chooser

March 29, 2016 Leave a comment

null oid not supported Telerik OpenAccess

February 18, 2016 Leave a comment

Error : Null oid not supported 

Stack trace
[ArgumentException: null oid not supported]
at Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
at OpenAccessRuntime.ExceptionWrapper.Throw()
at OpenAccessRuntime.common.StatesReturned.addImp(OID oid, State state, Boolean directFlag)
at OpenAccessRuntime.common.StatesReturned.add(OID key, State value_Renamed)
at OpenAccessRuntime.Relational.RelationalQueryResult.fetchManagedTypes(ApplicationContext context, Int32 fetchAmount, QueryResultContainer results)
at OpenAccessRuntime.Relational.RelationalQueryResult.fetchNextResultBatch(ApplicationContext context, QueryResultContainer results, Int32 fetchAmount)

 

Reason :

Its because of the there is an object where the id (Primary key) field contains a null.

if there is an entity having two fields set as Identity field. and one of the fields is purely unique (set a Primary Key in DB)  where as the other one is not so this kind of error raised by Telerik ORM.

Solution:

Telerik ORM is not supporting  ‘null’ values as part of the identity. Each member that makes up the identity of a class must have a non-null value. There is no workaround either to this problem.

Hope this help !