Post Back Function Name and Dynamic Form ID

K

Kevin Phifer

Is it possible to change the function name of the Postback
jscript function for a asp.net form. I'm gathering
content from multiple sources and can't have 2
__doPostBack 's on the same page. Also would like to be
able to dynamically change the form id, but it won't seems
to let me do a id="Form1<%# whatever %>" type thing.

I'm beginning the to think that I will have to create my
own "Page" class, but I would like to avoid this if
possible. If not, are there any carticles out there that
might point me in the right direction. Thanx in
advance....
 
N

Natty Gur

Hi,

1) you can render any function as you want, as long as the function set
__Eventtarget, __Eventargument set to correct values and the form submit
the event will occurred in the server.

2) You mean to change the form ID : this.FindControl ("WebForm9").ID =
"NattyGur";. can you explain why ?

Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 
K

Kevin Phifer

Part 2 worked great. But maybe i need to ask the first
question in a different way.....

I want to change the function name that asp.net uses to do
post backs ("__doPostBack") to something
like "__doBostBack1" or something like that. How do I go
about getting asp.net to use a different name for is JS
post back routine?
 
N

Natty Gur

Hi,

As far as I know you can use the Render function to replace __Dopostback
with _MyOwnPostBack :

override protected void Render(HtmlTextWriter writer )
{
StringBuilder oStringBuilder = new StringBuilder();
StringWriter oStringWriter = new StringWriter(oStringBuilder);
HtmlTextWriter oHtmlWriter = new HtmlTextWriter(oStringWriter);
base.Render(oHtmlWriter);

oStringBuilder = oStringBuilder.Replace("__dopostback",
"__dopostback1");
writer.Write(oStringBuilder.ToString());
}
Alternatively,

You can use Page.RegisterClientScriptBlock to render your own postback
function.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
J

Jacob Yang [MSFT]

Hi Kevin,

Based on my research and experience, the __doPostBack function was
generated by ASP.NET and we cannot rename it.

However, to my knowledge, we can implement your task by hooking the call to
this function. Please check out the following two articles for this idea.

HOW TO: Manually Post Back for Specific Events in an .aspx Page Using
Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;328923

How postback works in ASP.NET
http://www.xefteri.com/articles/dec102002/default.aspx

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
K

Kevin Phifer

Jacob,
What I'm trying to do is have the page rename the
__doPostBack Javascript function name. Currently I found
a way to do it by creating my own Inheriting from the Page
class and overriding the Rendering method. This, however,
seems to ineffectient, but may be the only way for me to
do it. The following is my inheritied class code:

public class NewPage : System.Web.UI.Page
{
public NewPage():base()
{
}

protected override void Render
(HtmlTextWriter writer)
{
StringBuilder sb = new
StringBuilder();
StringWriter sw = new StringWriter
(sb);
HtmlTextWriter htw = new
HtmlTextWriter(sw);
base.Render(htw);
string html = sb.ToString().Replace
("__doPostBack","__newDoPostBack");;

writer.Write (html);
}
}


This works with the following snippet of html:

function __newDoPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase
().indexOf("netscape") > -1) {
theform = document.forms
["sometingnew"];
}
else {
theform = document.sometingnew;
}
theform.__EVENTTARGET.value =
eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value =
eventArgument;
theform.submit();
}

.......{snip}....

<select name="DropDownList1" onchange="__newDoPostBack
('DropDownList1','')"

.......{snip}....


It does do what I want it to do, but I hate all the string
manipulation. What I was hoping for was a property or
method to set this value for the framework.

Is there another way to do this?
 
K

kevin

Repost (Forgot my nospam alias)
Jacob,
What I'm trying to do is have the page rename the
__doPostBack Javascript function name. Currently I found
a way to do it by creating my own Inheriting from the Page
class and overriding the Rendering method. This, however,
seems to ineffectient, but may be the only way for me to
do it. The following is my inheritied class code:

public class NewPage : System.Web.UI.Page
{
public NewPage():base()
{
}

protected override void Render
(HtmlTextWriter writer)
{
StringBuilder sb = new
StringBuilder();
StringWriter sw = new StringWriter
(sb);
HtmlTextWriter htw = new
HtmlTextWriter(sw);
base.Render(htw);
string html = sb.ToString().Replace
("__doPostBack","__newDoPostBack");;

writer.Write (html);
}
}


This works with the following snippet of html:

function __newDoPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase
().indexOf("netscape") > -1) {
theform = document.forms
["sometingnew"];
}
else {
theform = document.sometingnew;
}
theform.__EVENTTARGET.value =
eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value =
eventArgument;
theform.submit();
}

........{snip}....

<select name="DropDownList1" onchange="__newDoPostBack
('DropDownList1','')"

........{snip}....


It does do what I want it to do, but I hate all the string
manipulation. What I was hoping for was a property or
method to set this value for the framework.

Is there another way to do this?
 
K

Kevin Phifer

Repost (Forgot my nospam alias) one more time.....
Jacob,
What I'm trying to do is have the page rename the
__doPostBack Javascript function name. Currently I found
a way to do it by creating my own Inheriting from the Page
class and overriding the Rendering method. This, however,
seems to ineffectient, but may be the only way for me to
do it. The following is my inheritied class code:

public class NewPage : System.Web.UI.Page
{
public NewPage():base()
{
}

protected override void Render
(HtmlTextWriter writer)
{
StringBuilder sb = new
StringBuilder();
StringWriter sw = new StringWriter
(sb);
HtmlTextWriter htw = new
HtmlTextWriter(sw);
base.Render(htw);
string html = sb.ToString().Replace
("__doPostBack","__newDoPostBack");;

writer.Write (html);
}
}


This works with the following snippet of html:

function __newDoPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase
().indexOf("netscape") > -1) {
theform = document.forms
["sometingnew"];
}
else {
theform = document.sometingnew;
}
theform.__EVENTTARGET.value =
eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value =
eventArgument;
theform.submit();
}

.........{snip}....

<select name="DropDownList1" onchange="__newDoPostBack
('DropDownList1','')"

.........{snip}....


It does do what I want it to do, but I hate all the string
manipulation. What I was hoping for was a property or
method to set this value for the framework.

Is there another way to do this?
 
J

Jacob Yang [MSFT]

Hi Kevin,

Thank you for your update

After I posted my previous reply, I also tried the override of the Render
method. As you tried above, by overriding the Render method, we can
implement the task to change the __doPostBack function to any others.

Although this approach can be used to implement our task, it is not a usual
operation. That is why I didn't recommend you last time.

By discussing with some other experts in this field, it comes that there is
no direct method or property to change the name of this function.

Please let me know if it makes sense.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top