Pass Query String Variables from Form

I am creating an aspx page in sharepoint which needs to link to other pages that accept Query String variables. Those pages are ready to go.

I need to create a list of links which accept values from a form text box and pass to the next page.

For eg..

<script language="javascript" type="text/javascript">
private void menuredirect(object sender, System.EventArgs e)
{
    // Value sent using HttpResponse
    Response.Redirect("menus.aspx?sid="+RadioList.Value+"&date="+datetxt.Text);
}
</script>

<asp:TextBox runat="server"  id="datetxt"></asp:TextBox>

<asp:RadioButtonList runat="server" id="RadioList">
      <asp:ListItem Value="1019629">Alumni Cafe</asp:ListItem>
</asp:RadioButtonList>

<asp:Button runat="server" Text="Button" id="Button1" OnClientClick="menuredirect()"/>

This is not working. I am not sure what I am doing wrong. When I click it does not redirect to the next page.
LVL 2
BharBharAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bane83Commented:
There are a few things wrong with your javascript there.  Firstly, you're making your function call incorrectly.  Notice that in your OnClientClick you call menuredirect() however, menuredirect has a signature that requires two parameters.  The parameters are not necessary in javascript, so start by removing those.

Your next problem is the way you're referencing the RadioButtonList.  Firstly, the javascript won't know what it is since you're using the ASP.NET ID rather than the ClientID.  Next, a RadioButtonList is rendered as a span with several radiobuttons inside of it.  As such the RadioList.Value will return "undefined".  You would have to modify your javascript to loop through each child element of RadioList (this will contain both objects of type input (radio buttons) and span (the labels) until you find the radiobutton with its "checked" property set to true and use the value of that for the redirect.

In the end you will need something like this:

<script language="javascript" type="text/javascript">
private void menuredirect()
{
    var rbList = document.getElementById('RadioList');
    for (i = 0; i < rbList.childNodes.length; i++)
    {
        if (rbList.childNodes[i].checked == true)
        {
             Response.Redirect("menus.aspx?sid="+rbList.childNodes[i].value+"&date="+datetxt.Text);
             // You may also want to add a "break;" here to stop it from continuing to loop through the rest.
        }
    }
}
</script>

<asp:TextBox runat="server"  id="datetxt"></asp:TextBox>

<asp:RadioButtonList runat="server" id="RadioList">
      <asp:ListItem Value="1019629">Alumni Cafe</asp:ListItem>
</asp:RadioButtonList>

<asp:Button runat="server" Text="Button" id="Button1" OnClientClick="menuredirect()"/>
0
BharBharAuthor Commented:
Hey, Bane. Thanks for the input. I have corrected my code, however the result is still the same. When I click the button it looks like it redirects me to the same page. I see an error box on the bottom left corner of IE but it goes away.  Any thoughts? I am doing this within a sharepoint aspx page.
0
Bane83Commented:
Sorry, that was careless of me.  I missed the datetxt.Text part of your code and did a small mistake on the code to retrieve a javascript handle to the control.  Please revise this to be:

<script language="javascript" type="text/javascript">
private void menuredirect()
{
    var rbList = document.getElementById('<% =RadioList.ClientID %>');
    var datetxt = document.getElementById('<% =datetxt.ClientID %>');

    for (i = 0; i < rbList.childNodes.length; i++)
    {
        if (rbList.childNodes[i].checked == true)
        {
             Response.Redirect("menus.aspx?sid="+rbList.childNodes[i].value+"&date="+datetxt.value);
             // You may also want to add a "break;" here to stop it from continuing to loop through the rest.
        }
    }
}
</script>

If you still receive errors, it is also possible to debug javascript in IE (provided you have something installed to do this such as Visual Studio) by first (in IE) going to Tools -> Internet Options.  In the popup choose the Advanced tab and then under "Browsing" uncheck the 2nd and 3rd item ("Disable script debugging).  Once you do that, you can add a "debugger;" statement to the beginning of your javascript:

private void menuredirect()
{
    debugger;
    var rbList = document.getElementById('<% =RadioList.ClientID %>');

This will allow you to step through the code line by line and use the IDE to view the variables and any possible errors.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

net_susanCommented:
I'm pretty sure SharePoint doesn't let you use <% %>
0
BharBharAuthor Commented:
yes it doesnt. and thats the problem. how do i bind my link to a form control?
0
Bane83Commented:
My apologies, I've never used Sharepoint.  Although I'm not sure this is the best way to do it in SharePoint, you could view the source of the rendered page and get the ID of the controls you require.

You would then use
var ctrl = document.getElementById('controlID');
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.