开发者

.net div trigger postback

开发者 https://www.devze.com 2023-02-09 20:56 出处:网络
I would like to make a custom button, that will display 3 data bound labels and some other text. I would like this button to act fully like a asp:button control. Currently The only idea I have is to s

I would like to make a custom button, that will display 3 data bound labels and some other text. I would like this button to act fully like a asp:button control. Currently The only idea I have is to surround the labels with a div, trigger the divs click event to use a javascript event which causes a postback. I do not want this, I would like to create a custom button that wires up the postback like a normal asp:butt开发者_开发问答on control does. Any ideas on how to do this would be great thank you very much.

    <div class="someClass">
        <div>
          <asp:Label ID="lblONE" runat="server" Text='ONE'></asp:Label>
        </div>
        <div>
          <asp:Label ID="lblTWO" runat="server" Text='TWO'></asp:Label>
        </div>
        <div>
          <asp:Label ID="lblTHREE" runat='server' Text='THREE'></asp:Label>
        </div>
   </div>

I have applied css to the elements and want the button to end up looking like this. Except where it says bob steve mark you can sub in ONE TWO THREE respectively

Button Layout

.net div trigger postback


You can achieve custom layout by using LinkButton (as LinkButton implements IButtonControll by default)

<style type="text/css">
.button {
    border: solid thin black; text-decoration: none; display: block; height: 40px;
}
.one {
    color: green; text-transform: uppercase;
}
.two {
    color: red; text-transform: lowercase;
}
.three {
    color: blue; text-transform: capitalize;
}
</style>

    <asp:LinkButton runat="server" ID="LinkButton1" CssClass="button">
    <div class="one">ONE</div>
    <div class="two">TWO</div>
    <div class="three">THREE</div>
    </asp:LinkButton>

// as you need DataBinding, so

    <asp:LinkButton runat="server" ID="LinkButton1" CssClass="button">
    <div class="one"><%#Eval("ONE")%></div>
    <div class="two"><%#Eval("TWO")%></div>
    <div class="three"><%#Eval("THREE")%></div>
    </asp:LinkButton>


You can use the LinkButton control and assign the text of each button through code. Similarly, you could also assign the CommandName and CommandArgument parameters to each LinkButton control as you render them, so they be processed uniquely if needs be.

If you want the entire text listed above to be a part of the LinkButton, you should be able to put all of the text and apply it to the Text property of the LinkButton. You just have to be careful on how your format your HTML.

From there you can process the click event of the button(s) accordingly.


For what I think you're trying to accomplish, you're probably stuck with javascript. However, you can use javascript in your div container's onClick event to "wire" up the postback for your "button". __doPostBack(document.getElementById('divID'), 'customArgument');

You can then check if your div caused the post back in your code-behind like this (C#):

if (Request.Form["__EVENTTARGET"] == "divID"){}

Is this what you're looking for?

0

精彩评论

暂无评论...
验证码 换一张
取 消