Archive

Archive for the ‘javascript’ Category

Troubleshooting with Asynchronous post back errors or Error occurred in Ajax control toolkit.

February 7, 2012 4 comments

Its often hard to identify the error occurred in scripts , specially with asynchronous post backs and Ajax update panel.

A good and affective way to identify is described by Mr. Aqeel (An experienced SharePoint developer) to me and i am very glad write it here.

ScriptManager.GetCurrent(this.Page).AsyncPostBackError += new EventHandler<AsyncPostBackErrorEventArgs>(UC_AsyncPostBackError);

I have user control which populates the data and some scripts are being attached to it.

so declared the event  AsyncPostBackError in page load of that user control.

Then into the even of AsyncPostBackError.

void UC_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
      {
          try
          {
              string exc = e.Exception.Message;
          }
          catch (Exception ex)
          {

              throw;
          }
      }

This would let you know the exact exception occurred.

Water marking for asp:textbox using javascript

A while ago i had a task to implement water mark on asp:textbox , well a short one but its always good to have the tasks which are not done before as they provides room for improvement and learning. In my opinion its not bad to learn even a single character a day .

Simple javascript function to deal in.

<script
type=”text/javascript”
language=”javascript”>
function
clearWaterMark()
{


var text = document.getElementById(‘<%=txtExample.ClientID %>’).value;


if(text.match(“^Example”))

{

document.getElementById(‘<%=txtExample.ClientID %>’).value= ;

}

}

function addWaterMark()

{ if(document.getElementById(‘<%= txtExample.ClientID %>’).value== )

{

document.getElementById(‘<%= txtExample.ClientID %>’).value=“Example C:\\FileName.p12”;

}

}
</script>

 

<asp:TextBox
ID=”txtExample”
Width=”233px”
runat=”server”
Font-Size=”XX-Small”
ToolTip=”Type full path of certificate including extention.”
onClick=”clearWaterMark()”
onBlur=”addWaterMark()”>Example C:\Certificate.p12</asp:TextBox>

 

Javascript functions are called on events

  • onClick=”clearWaterMark()”
    //Checks if there is text in textbox starting with “Example” then clearing that.
  • onBlur=”addWaterMark()” // Checkis if there is no text in textbox then adding the text to textbox

 

Happy Coding J