Microsoft Content Management Server - Vb Event handling in a control?

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > March 2004 > Vb Event handling in a control?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Vb Event handling in a control?
BrettG

2004-03-30, 11:43 am

Hi,

I had previously built a very simple web user control in C# and I'm
trying to port it to vb.net. The control was basically two textboxes
for meta keywords and meta description, the values are saved to custom
properties and rendered when published as meta tags.

I'd been getting the values of the textboxes during the _TextChanged
events and setting class level string variables to their values.
Example:
--------------------------------------------------------
private void txtMetaDescription_TextChanged(object sender,
System.EventArgs e)
{
_sDescription = txtMetaDescription.Text;
}

Then I had added event handlers for save/create events in OnInit:
Example:
--------------------------------------------------------
WebAuthorContext editState = WebAuthorContext.Current;

if(editState.Mode == WebAuthorContextMode.AuthoringNew ||
editState.Mode == WebAuthorContextMode.AuthoringReedit )
{
this.Visible = true;
if (editState.Mode == WebAuthorContextMode.AuthoringNew)
{
Microsoft.ContentManagement.WebControls.WebAuthorContext.Current.CreatedPostingEvent
+= new Microsoft.ContentManagement.WebControls.WebAuthorPostingEventHandler(this.Create_Posting);
}
else
{
Microsoft.ContentManagement.WebControls.WebAuthorContext.Current.SavePostingEvent
+= new Microsoft.ContentManagement.WebControls.WebAuthorPostingEventHandler(this.Save_Posting);
}
}
else
{
this.Visible = false;
}


Lastly the actual value setting was in my event handlers:
Example:
--------------------------------------------------------
private void Save_Posting(object sender,
Microsoft.ContentManagement.WebControls.WebAuthorPostingEventArgs
args)
{
if (_sDescription != string.Empty)
CmsUtil.CustomCmsProperties.SavePostingProperty(_sDescription,
"MetaDescription",args.Posting);
if ( _sKeywords != string.Empty)
CmsUtil.CustomCmsProperties.SavePostingProperty(_sKeywords,
"MetaKeywords",args.Posting);
}
//----------------------------------------------------------------------------------


I've seen examples that show how to put event handlers in global.asax,
but is there a way that I can add this into my control? Is there a way
that I can add this to global.asax and still get the values from my
textboxes without having to use session?

Any advice would be much appreciated, I'm sure that I can come up with
a cludgy fix but if you have any suggestions I'd like to hear them.

Thanks,

Brett
Stefan [MSFT]

2004-03-30, 11:43 am

Hi Brett,

the values from your text boxes are available in the global.asax by reading
the relevant request.form fields.

Cheers,
Stefan.

--
This posting is provided "AS IS" with no warranties, and confers no rights.


"BrettG" <brettgarnier@yahoo.com> wrote in message
news:aded4e5e.0403300800.31b262c2@posting.google.com...
> Hi,
>
> I had previously built a very simple web user control in C# and I'm
> trying to port it to vb.net. The control was basically two textboxes
> for meta keywords and meta description, the values are saved to custom
> properties and rendered when published as meta tags.
>
> I'd been getting the values of the textboxes during the _TextChanged
> events and setting class level string variables to their values.
> Example:
> --------------------------------------------------------
> private void txtMetaDescription_TextChanged(object sender,
> System.EventArgs e)
> {
> _sDescription = txtMetaDescription.Text;
> }
>
> Then I had added event handlers for save/create events in OnInit:
> Example:
> --------------------------------------------------------
> WebAuthorContext editState = WebAuthorContext.Current;
>
> if(editState.Mode == WebAuthorContextMode.AuthoringNew ||
> editState.Mode == WebAuthorContextMode.AuthoringReedit )
> {
> this.Visible = true;
> if (editState.Mode == WebAuthorContextMode.AuthoringNew)
> {
>

Microsoft.ContentManagement.WebControls.WebAuthorContext.Current.CreatedPost
ingEvent
> += new

Microsoft.ContentManagement.WebControls.WebAuthorPostingEventHandler(this.Cr
eate_Posting);
> }
> else
> {
>

Microsoft.ContentManagement.WebControls.WebAuthorContext.Current.SavePosting
Event
> += new

Microsoft.ContentManagement.WebControls.WebAuthorPostingEventHandler(this.Sa
ve_Posting);
> }
> }
> else
> {
> this.Visible = false;
> }
>
>
> Lastly the actual value setting was in my event handlers:
> Example:
> --------------------------------------------------------
> private void Save_Posting(object sender,
> Microsoft.ContentManagement.WebControls.WebAuthorPostingEventArgs
> args)
> {
> if (_sDescription != string.Empty)
> CmsUtil.CustomCmsProperties.SavePostingProperty(_sDescription,
> "MetaDescription",args.Posting);
> if ( _sKeywords != string.Empty)
> CmsUtil.CustomCmsProperties.SavePostingProperty(_sKeywords,
> "MetaKeywords",args.Posting);
> }
>

//--------------------------------------------------------------------------
--------
>
>
> I've seen examples that show how to put event handlers in global.asax,
> but is there a way that I can add this into my control? Is there a way
> that I can add this to global.asax and still get the values from my
> textboxes without having to use session?
>
> Any advice would be much appreciated, I'm sure that I can come up with
> a cludgy fix but if you have any suggestions I'd like to hear them.
>
> Thanks,
>
> Brett



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com