Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

asp.net get value from args on postback from javascript, _DoPostBackWithOptions

Posted on 2013-05-20
2
Medium Priority
?
859 Views
Last Modified: 2013-05-22
I am building a list of controls in code behind and putting an id# in a hyperlink.
an HTML hyperlink, not building asp.net controls. (only because I cant figure that out )
I can get it to postback to a button but can't get a value from the postback agument.

 Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'get arg and do something.

end sub

I tried this but cant get the values when the post back happens - it goes to the button1:
<a href="#" onclick="j WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('button1','12', true, &quot;&quot;, &quot;&quot;, false, false))"   /><br />

<a href="#" onclick="j WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('button1','44', true, &quot;&quot;, &quot;&quot;, false, false))"   />


I need to list  values - somehow - and when clicking it, it go to code behind with the value of the line.

not wanting to use a gridview.

I have loaded jquery and jquery moble
I'm using vb,net too

thanks, any comments are appreciated.
john
0
Comment
Question by:john
2 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 2000 total points
ID: 39183898
You should use ___doPostBack(), check:
http://www.codedigest.com/Articles/ASPNET/320_Doing_or_Raising_Postback_using___doPostBack()_function_from_Javascript_in_AspNet.aspx

In your case the markup will be as follows:
<a href="#" onclick=""javascript:__doPostBack('button1','44')">LinkButton</a>

Open in new window


in your VB code you can get the control id using ('button1')
Request.Params.Get("__EVENTTARGET")
and the argument('44')
Request.Params.Get("__EVENTARGUMENT")

and then add some if logic to call the button handler as a new method to avoid using event args
0
 

Author Closing Comment

by:john
ID: 39189765
got it I had to add

EnableEventValidation="false"
and
 AutoEventWireup="true"

at top of page,
thanks
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question