__doPostBack Arguments question

G

GaryDean

below is the html of two dropdownlists as they are rendered. The first was
created with Postback = false and I added the
onchange="myFunction('DropDownList1,'') in code. I made this look very much
like the asp generated onchange attribute in the second dropdown where
postback was set as true.

In the standard DropDownList2 the second argument is called eventArgument.
although the call to __doPostBack has it as ' ' there must be something that
gets passed in it because it has a value when it gets to the javascript
__doPostback function. I figured that maybe the code in the DropDwonList
object is putting the necessary data into that argument somehow.

I have attempted to simulate that with dropdown1 but the second argument is
indeed blank when it gets to the myFuction argument.

So, the questions is: how does the eventargument data get into the second
argument in the case of DropDownList2?? I hope to make it do the same thing
when going to my javascript function.




<select name="DropDownList1" id="DropDownList1"
onchange="myFunction('DropDownList1','')" style="width:128px;Z-INDEX: 101;
LEFT: 80px; POSITION: absolute; TOP: 32px">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>

</select>
<select name="DropDownList2" onchange="__doPostBack('DropDownList2','')"
language="javascript" id="DropDownList2" style="width:120px;Z-INDEX: 102;
LEFT: 296px; POSITION: absolute; TOP: 32px">
<option value="three3">three3</option>
<option value="4">four</option>
<option value="5">five</option>
 
E

Erik Funkenbusch

I have attempted to simulate that with dropdown1 but the second argument is
indeed blank when it gets to the myFuction argument.

There are a number of things that go on in the background here, that you
will have to recreate to do this.

First, if you look at the __doPostBack function, you will notice that it
encodes the control into the __EVENTTARGET hidden field. This is what
allows the HttpModule that your pages derive from (usually Page) to know
that there was an event it was processing.

Once the HttpModule gets it, it will then take that value, decode it, then
extract the value from the postback information for the control.

ie, something like Request("DropDownList1")
 
G

GaryDean

it encodes it by....
theform.__EVENTARGUMENT.value = eventArgument;

but my point is that when MY javascript function gets eventArgument it is a
blank string so I think this is happening before the transformations you
refer to.

Gary
 
S

Steven Cheng[MSFT]

Thanks for Erik's input.

Hi Gary, as for the ASP.NET's generated __doPostBack function, it will
accept some additional data when the postback is generted from some nested
subcontrols in a container control. Also, since the function is rendered
out ,it's code logic is quite straighforward there. BTW, if you want to do
your own postback and pass some additional argument, you can consider
putting a custom html input hidden field which store your custom data.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


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



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

GaryDean

Steven,
I think I need to get more generic about what I am trying to do....

Almost all of the web controls call the __Postback function and they get the
data to it that I eventually get in my various web control events. I want
to find a way to pass that same information to a javascript function. for
instance if it's a dropdown I want to get selectedindex, selectedvalue, etc.

I figured out how to do this for the Calendar control because it was nice
enough to provide me with a dayrender event where I can substitute my own
call for the postback call - but that call was simple, it just passed a
date.

So, is there a way to do this? - for the dropdown, the listbox, the
checkboxlist, etc?

(fyi - the reason I want to do this is because I have a 3rd party AJAX
control that the javascript can call with the data and that is an easy way
to refresh just that AJAX area).
 
S

Steven Cheng[MSFT]

Thanks for your response Gary,

So you're wantting to replace those built-in control's postback handler to
your own client function? If this is the case, it'll be abit hard to do so
since the postback script handler generation is encapsulated internally and
not recommended to change it. If you do want to customize it, you may need
to consider create sub class derived from the built-in one and override the
rendering specific methods.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


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



Get Secure! 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,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top