effecting postback without auto postback controls

P

Psych971

Hi, I'm wondering how I can generate a postback using javascript on a page
that does not have any controls with the auto-postback property set to true.
I know I can just use the submit() function but this triggers page
validation which I do not want. What I'm trying to do is dynamically write
in a hyperlink that when clicked will remove an item from the form, so I
don't want any validation to occur because the form isn't being submitted at
that point. And because there are no auto-postback controls the server does
not write in the javascript which would be used to effect the postback so I
can't just insert "onclick("__doPostBack('','');")". Is there an easy way to
do this without manually inserting a bunch of javascript code? More
concisely... How do I manually effect a postback without triggering page
validation?

Thanks!
Richard
 
K

Karl Seguin

Although there is a way to do postback without manually inserting all the
javascript, why not just use a linkbutton (hence all javascript is written
for you) and simply set it's CausesValidation to false?

Karl
 
P

Psych971

Because I'm writing dynamically into the response file i don't think you can
insert asp controls, can you?

thanks,
richard
 
K

Karl Seguin

Are you dynamically creating it via

LinkButton lb = new LinkButton()
someControl.Controls.Add(lb);

or are you actually writing it to the html/aspx file via a streamwriter or
something? If it's the first one, don't see why you can't add
causesValidatation = false...if its the second case (god why?) then you are
in trouble...

Karl
 
P

Psych971

You've shown me the light! I was doing it the second way but it my first
..net page so what'd you expect? :) Will switch to LinkButton.. thanks so
much! ASP.NET rules!!

peace out,
richard
 
B

bruce barker

I just wrote a control to do this. basically it registers a javascript
function doPostBack(arg), that client code can call. I added a standard
server event handling, so the client can call a know routine.

string script = "<script language=\"JavaScript\">function
doPostBack(a,v,fn){__doPostBack('"
+ this.UniqueID + "',a,v,fn);}</script>\n";
if(!this.Page.IsClientScriptBlockRegistered("doPostBack"))
this.Page.RegisterClientScriptBlock("doPostBack",script);
Page.GetPostBackEventReference(this);

the trick is, Page.GetPostBackEventReference(this), this call is what
triggers .net generating the autopostback code.

-- bruce (sqlwork.com)


| Hi, I'm wondering how I can generate a postback using javascript on a page
| that does not have any controls with the auto-postback property set to
true.
| I know I can just use the submit() function but this triggers page
| validation which I do not want. What I'm trying to do is dynamically write
| in a hyperlink that when clicked will remove an item from the form, so I
| don't want any validation to occur because the form isn't being submitted
at
| that point. And because there are no auto-postback controls the server
does
| not write in the javascript which would be used to effect the postback so
I
| can't just insert "onclick("__doPostBack('','');")". Is there an easy way
to
| do this without manually inserting a bunch of javascript code? More
| concisely... How do I manually effect a postback without triggering page
| validation?
|
| Thanks!
| Richard
|
|
 

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,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top