This may be pretty obvious to more seasoned C# web developers, but if you’re fresh with web part development (like me) this may come in handy.
Last week I was working on a feedback form. The user enters in some data in an HTML form, hits the submit button, and Sharepoint sends an email to a preset email address. Problem was, I had no idea how to get the value from the POST event.
Now one of the problems is that Sharepoint puts a whole bunch of garble in from of the ID tag for each form element. So if you assign a constant value to the ID tag like this:
It will end up looking something like this:
That’s pretty messy. A long very unfriendly ID tag for sure. So I figured why don’t we make a loop and just look for our ID tag as part of the key. That way we don’t have to know the exact name, but rather just the part we named it.
{
if (key.Contains(ID_COMMENT_BODY_TEXTBOX))
_formattedCommentBodyString = this.Page.Request.Form[key];
else if (key.Contains(ID_COMMENT_TITLE_TEXTBOX))
_formattedCommentTitleString = this.Page.Request.Form[key];
}
Note that you can put multiple elements in the loop, and therefore assign more then just one string in each loop (i.e. if you have 4 form elements, don’t make 4 loops… stick them all in the same for each loop). The constants I’m referring to above I’ve assigned to the form elements that I want to retrieve the data from:
oCommentBodyTextBox.TextMode = TextBoxMode.MultiLine;
oCommentBodyTextBox.ID = ID_COMMENT_BODY_TEXTBOX;
oCommentBodyTextBox.CssClass = CSS_COMMENT_BODY_TEXTBOX;
Leave a Reply