Solved

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

Posted on 2013-05-20
2
819 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 35

Accepted Solution

by:
Miguel Oz earned 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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 …
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 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