By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,247 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,247 IT Pros & Developers. It's quick & easy.

executing a server method after page is rendered

P: n/a
Hi all

I am calling a method in a Page_Load event that makes use of a value
from a text box.

Unfortunately the textbox value is only set after a javascript runs
and the page is rendered. Therefore the textbox is actually empty when
the Page_Load event fires.

Is there a way to execute the method after the javascript has run and
the page has rendered.

I can do it by adding a button and placing the call to the method in
its onClick event but this is not acceptable in terms of user
interface. It must happen onLoad.

Can I maybe "fake" a button click?

Thanks in advance

John

Aug 27 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Thank you Mukesh

This gives me the same type of problem. I cannot get the value of the
hidden field until after the page has completely rendered so i can't
refer to it in the page_load event.

John

On 28 Aug, 10:22, Mukesh Zala <MukeshZ...@discussions.microsoft.com>
wrote:
My understanding says you need following funcationality
1) before page load some javascript executes
2) on page load event some server side method uses value of textbox.
you can try in this way.
declare html hidden control with runat server side, when javascript executes
store value of textbox in hidden field.
Use hidden field value in server side method during page load.
Bye
Aug 28 '07 #2

P: n/a
On Aug 27, 10:42 pm, "jphayc...@googlemail.com"
<jphayc...@googlemail.comwrote:
Hi all

I am calling a method in a Page_Load event that makes use of a value
from a text box.

Unfortunately the textbox value is only set after a javascript runs
and the page is rendered. Therefore the textbox is actually empty when
the Page_Load event fires.

Is there a way to execute the method after the javascript has run and
the page has rendered.

I can do it by adding a button and placing the call to the method in
its onClick event but this is not acceptable in terms of user
interface. It must happen onLoad.

Can I maybe "fake" a button click?

Thanks in advance

John
As I see you have to do something with value in textbox after it was
changed.
Try to use OnTextChanged event handler insted of Page_Load:

<asp:TextBox ID="TextBox1" runat=server AutoPostBack=true
OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
//call your method here
}

Regards,
Mykola
http://marss.co.ua

Aug 28 '07 #3

P: n/a
Thank you Mykola

Alas, that still requires user interaction after the page has loaded.
I need this to happen without the user clicking a button or changing
text. The value of the textbox is populated by a javascript and the
OnTextChanged event isn't fired by this action.

John

As I see you have to do something with value in textbox after it was
changed.
Try to use OnTextChanged event handler insted of Page_Load:

<asp:TextBox ID="TextBox1" runat=server AutoPostBack=true
OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
//call your method here

}

Regards,
Mykolahttp://marss.co.ua- Hide quoted text -

- Show quoted text -

Aug 28 '07 #4

P: n/a
On 28 , 17:16, "jphayc...@googlemail.com"
<jphayc...@googlemail.comwrote:
Thank you Mykola

Alas, that still requires user interaction after the page has loaded.
I need this to happen without the user clicking a button or changing
text. The value of the textbox is populated by a javascript and the
OnTextChanged event isn't fired by this action.

John
As I see you have to do something with value in textbox after it was
changed.
Try to use OnTextChanged event handler insted of Page_Load:
<asp:TextBox ID="TextBox1" runat=server AutoPostBack=true
OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
//call your method here
}
Regards,
Mykolahttp://marss.co.ua-Hide quoted text -
- Show quoted text -
View page source and find how ASP.Net rendered textbox. It have to be
something like this:
<input name="TextBox1" type="text"
onchange="javascript:setTimeout('__doPostBack(\'Te xtBox1\',\'\')',
0)" ...

Call __doPostBack('TextBox1','') in your javascript after you changed
value..

Regards,
Mykola
http://marss.co.ua

Aug 28 '07 #5

P: n/a
Hi Mykola

Thank you

This worked but it keeps firing repeatedly. Do you know how i can make
it postback only once?

John

View page source and find how ASP.Net rendered textbox. It have to be
something like this:
<input name="TextBox1" type="text"
onchange="javascript:setTimeout('__doPostBack(\'Te xtBox1\',\'\')',
0)" ...

Call __doPostBack('TextBox1','') in your javascript after you changed
value..

Regards,
Mykolahttp://marss.co.ua- Hide quoted text -

- Show quoted text -

Aug 28 '07 #6

P: n/a
On 28 , 19:24, "jphayc...@googlemail.com"
<jphayc...@googlemail.comwrote:
This worked but it keeps firing repeatedly. Do you know how i can make
it postback only once?

Hi John,
The method itself does not cause looping. It may be caused by program
logic. It is hard to me to give more definite advice. Perhaps, if you
want to call some method in Page_Load (not in textbox's OnTextChanged
event handler) you have to test whether this postback was caused by
change in textbox. I mean that if you call __doPostBack('TextBox1','')
in javascript then you can process this postback in Page_Load
if (Request.Params["__EVENTTARGET"] == "TextBox1")
{
//call some method here
}

Regards,
Mykola
http://marss.co.ua

Aug 29 '07 #7

P: n/a
Thanks again Mykola

The problem seems to be that each time the page loads the javascript
is executed and this forces a postback so it gets stuck in a loop.

I may have to rethink how I'm going about this

Cheers

John

On 29 Aug, 09:14, marss <marss...@gmail.comwrote:
Hi John,
The method itself does not cause looping. It may be caused by program
logic. It is hard to me to give more definite advice. Perhaps, if you
want to call some method in Page_Load (not in textbox's OnTextChanged
event handler) you have to test whether this postback was caused by
change in textbox. I mean that if you call __doPostBack('TextBox1','')
in javascript then you can process this postback in Page_Load
if (Request.Params["__EVENTTARGET"] == "TextBox1")
{
//call some method here

}

Regards,
Mykolahttp://marss.co.ua

Aug 29 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.