Solved

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

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now