Showing posts with label register. Show all posts
Showing posts with label register. Show all posts

Monday, March 26, 2012

Access HiddenField when using Update Panel

Hello,

I have a page that using update panel. I register hiddenfield using ScriptManager.Registerhiddenfield. I want to get the value, but it always failed.

This is the code :

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = this.Request.Form["__vsKey"];
}

protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterHiddenField(this, "__vsKey", "myValue");
}

When I don't use update panel, it's working properly. Do anyone know how to access the value?

Thanks before

What kind of error you are getting ?

To register a hidden field for a control that is inside anUpdatePanel control so that the field is registered only when the panel is updated, use theRegisterHiddenField(Control, String, String) overload of this method. If you are registering a hidden field that does not pertain to partial-page updates and you want to register a hidden field only one time during initial page rendering, use theRegisterHiddenField(String, String) method of theClientScriptManager class.


The problem is I don't get the value from this hiddenfield when using UpdatePanel. It always return null value.

I'm using a button to register the hiddenfield

protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterHiddenField(this, "__vsKey", "myValue");
}

And when the page load, a label display the hiddenfield value

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = this.Request.Form["__vsKey"];
}

But, the label display nothing when I use UpdatePanel.

Access class from inline frame

I have a composite control with associated javascript. The javascript uses registerClass to register a class. What I'd like to be able to do is access a method in this class from outwith my control, from another frame to be specific. Normally I'd simply do parent.class.method but when I try that I get a "not a function" error. When I try alerting the class I get the javascript code for it and not the instance.

So how do I get the instance of the class registered with registerClass from within another frame, if it is at all possible.

Thanks.

Hi

Would you please provide us with your code,so we can reproduce this issue quicklier?

Thanks


Thanks for the reply.

This is the javascript code for the control, I have snipped some of the functions to cut the length.

Type.registerNamespace('number45');

number45.editor = function(element) {

number45.editor.initializeBase(this, [element]);

this.type = 'editor';
this.editor_obj_id = '';
this.toolbar_id = '';
this.colors = '';

this.popups = new Array();
this.buttons = new Array();
this.popupshowing = '';
};

number45.editor.prototype = {

initialize: function()
{
number45.editor.callBaseMethod(this, 'initialize');

this.editor_obj = document.getElementById(this.editor_obj_id);

var documentClick = Function.createDelegate(this, this.close);
$addHandler(document, 'click', documentClick);
},

dispose : function() {
$clearHandlers(this.get_element());

number45.editor.callBaseMethod(this, 'dispose');
},

get_editor_obj_id: function()
{
return this.editor_obj_id;
},

set_editor_obj_id: function(value)
{
this.editor_obj_id = value;
},

insertText : function(newtext) {
this.checkFocus();
if (document.selection)
document.selection.createRange().text = newtext;
else {
if (typeof(this.editor_obj.selectionStart) != 'undefined') {
this.editor_obj.value = this.editor_obj.value.substr(0, this.editor_obj.selectionStart) + newtext + this.editor_obj.value.substr(this.editor_obj.selectionEnd, this.editor_obj.value.length);
} else {
this.editor_obj.value += newtext;
}
}
},

insertAttachment : function(attachment) {
var start_tag = '[image]';
var end_tag = '[/image]'

this.insertText( start_tag + attachment + end_tag );
},

}

number45.editor.registerClass('number45.editor', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

function stop_bubble(obj) {
if (!obj) {
window.event.cancelBubble=true;
return window.event;
} else {
obj.stopPropagation();
return obj;
}
};

It is the functioninsertAttachment I want to call from the inline frame. I have tried usingparent.number45.editor.insertAttachment('x'), this is what causes the 'not a function' error. When I try alertingparent.number45.editor I get the body of thefunction(element) shown.