Wednesday, October 9, 2013

.NET Regex - using $ and \r\n

Symptom:
I have a list of values in a textbox...

apple
banana
cherry
donut

In a textbox it looks like this:

TextBox1.Text = "apple\r\nbanana\r\ncherry\r\ndonut\r\n";

Let's parse through the list using a pattern and do a replace...

Then I'll do a replace...

TextBox1.Text = Regex.Replace(TextBox1.Text,  "^(.*)$" , "I like to put $1 on my plate.\r\n", RegexOptions.Multiline);

I would expect to see this:

I like to put apple on my plate.
I like to put banana on my plate.
I like to put cherry on my plate.
I like to put donut on my plate.

Instead, I see this:

I like to put apple
 on my plate.
I like to put banana
 on my plate.
I like to put cherry
 on my plate.
I like to put donut
 on my plate.

It turns out that $ is matching \n, but not \r.

Solution:

Change to this and it worked as expected:

TextBox1.Text = Regex.Replace(TextBox1.Text,  "^(.*)\r\n" , "I like to put $1 on my plate.\r\n", RegexOptions.Multiline);

Thursday, January 24, 2013

UpdatePanel doesn't like the ViewState being tampered with!


Symptom:
Previous instances of RadAjaxPanel were replaced with UpdatePanel.  Suddenly, controls within that page no longer postback.

Sample Code:
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
    <ContentTemplate>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
    </ContentTemplate>
</asp:UpdatePanel>

protected void Button1_Click(object sender, EventArgs e)
{
Button1.Text = DateTime.Now.ToString();
}

protected void Button2_Click(object sender, EventArgs e)
{
Button2.Text = DateTime.Now.ToString();
}

When alternating clicks between Button1 and Button2, I would expect that the clicked button would update with the current time.  Instead, the button values were clearing.


Solution:
It turns out this was specific to a certain page.  On a normal page, it worked fine.  On the page with these symptoms, I discovered it was related to a solution that implimented due to a large ViewState.  I was overriding SavePageStateToPersistenceMedium and LoadPageStateFromPersistenceMedium and that was causing the UpdatePanel to fail when saving the ViewState information to the Cache.

Can't publish files in Visual Studio 2012


Symptom: 
When publishing files to a local drive with Visual Studio 2012, there seems to be no files in the destination directory.

Additional Symptoms:
- The My Project folder has some read-only .pubxml files that contain settings for publishing.  Deleting them seems to make deploying work again.
- After a Get Latest from TFS, my previously successful Publish settings are overridden with another team member's settings.

Solution:
When publishing a project, give the profile name something unique like your own name.  This will make a seperate .pubxml file with your settings.  Other team members using unique profiles with their own names should no longer affect your settings.  When they change their profile settings, their .pubxml file will be checked out and updated accordingly.

Friday, November 23, 2012

Not receiving MMS w/ ting on my Samsung SIII

Symptom:  People did not receive pictures we sent and we did not receive pictures that they sent.

Environment:
Pam using a Samsung Galaxy SIII, stock rom, rooted, but without the latest patch.
James using a Samsung Galaxy SIII, CM10 rom, using cm-10-20121118-NIGHTLY

Solution for Pam's phone:

  • dial ##DATA#
  • select Edit
  • enter MSL (obtain from ting, or go to the website, find Account, Device Settings, Select the phone number, and the MSL is under it)
  • select Others
  • select MMSC URL
  • change from http://mms.sprintpcs.com to http://mms.plspictures.com
  • save and reboot


Solution for James's phone:


  • It seems there was no obvious way to natively edit the MMS setting with CM10.  Various sources indicated I needed to edit a file.  To make things easier, I installed DropBear SSH server.
    https://play.google.com/store/apps/details?id=me.shkschneider.dropbearserver
  • SSH in, then remount the file system:
    • root@android:/ # cd /system/etc
    • root@android:/system/etc # mount -o rw,remount /system
  • Using vi, I altered /system/etc/apns-conf.xml to replace references for mms.sprintpcs.com to be mms.plspictures.com
  • Rebooted, MMS now works.  Reboot may not have been necessary even.



Wednesday, October 3, 2012

Getting the Repeater row index from the LinkButton


This is one I am posting for my own reference so I can find it easier...  When Clicking a LinkButton in a Repeater, I needed the index available to modify a cached DataTable.

Situation:  Getting the Repeater row index from the LinkButton

Solution:

        LinkButton lnkButton = sender as LinkButton;
        int RepeaterItemIndex = ((RepeaterItem)lnkButton.NamingContainer).ItemIndex;

Credit to kaushalparik27 at http://forums.asp.net/t/1333400.aspx/1

Tuesday, October 2, 2012

Scroll after postback


Situation: Button inside of a GridView fires the Command event and needs to scroll to the bottom of the page.

Solution:  Use an anchor tag, then use ClientScript.RegisterStartupScript on the end of the event method to scroll to it.

Credit goes to http://forums.asp.net/t/1311972.aspx/1

Monday, August 13, 2012

SQL string splitter


I really prefer to give credit for these types of things, but I don't remember where I found it :(

Basic syntax... select dbo.FN_STRING_HELPER_SPLIT('My name is James', ' ', 4) will return 'James'



CREATE FUNCTION [dbo].FN_STRING_HELPER_SPLIT
(
  @strToSplit as varchar(4000),
  @delimiter as varchar(50),
  @columnToReturn as int
)
RETURNS varchar(25)
AS
BEGIN
  -- Declartion of the return variable
  DECLARE @i as int
  DECLARE @occurrences as int
  DECLARE @delimiterIndex as int
  DECLARE @actSplitValue as varchar(4000)
 
  -- T-SQL statements to compute the return value here
  SET @i = 1
  SET @delimiterIndex = 1
 
  WHILE @i <= @columnToReturn
  BEGIN
    SET @delimiterIndex = CHARINDEX(@delimiter, @strToSplit)
    -- if not found end while
    SET @actSplitValue = @strToSplit
    IF @delimiterIndex = 0 BEGIN
      BREAK
    END
    SET @actSplitValue = LEFT(@strToSplit, @delimiterIndex - 1)
    -- SUBSTRING(string, von, bis)
    SET @strToSplit = SUBSTRING(@strToSplit ,@delimiterIndex +1, LEN(@strToSplit)- @delimiterIndex)
    SET @i = @i + 1
  END
  -- the result of the function
  RETURN @actSplitValue
END